Can you use firebase "callable functions" in angularfire2? - firebase

Is it possible to use "Callable Functions" together with AngularFire2?
Since AngularFireModule already calls initializeApp, I am not sure how to follow the instructions here?
I guess I should not call initializeApp() multiple times?

AngularFire2 is built on top of the regular Firebase JavaScript SDK. That means that anything that's possible in the JavaScript SDK, is also possible from within AngularFire2. If the action is related to showing data from Firebase in UI elements, there may be a wrapper from AngularFire. But even if there is no wrapper, you can access the JavaScript SDK directly.
So: Yes, it is possible to invoke Callable Cloud Functions from AngularFire2. You should indeed only initialize the app once, unless you're trying to access multiple projects.
If you're having trouble making this work, post the minimal, complete code that reproduces where you're stuck.

Related

Is there a way to remove ember-data from emberfire?

My app does not use ember-data, it uses only apollo for graphql to retrieve/manage data.
But after installing emberfire, we must have to install ember-data too.
We just use emberfire/firebase for authentication :)
If I try to remove it I've got an error:
Cannot find module 'ember-data/package.json' from '/Users/bruno/octane-graphql/node_modules/emberfire'
The solution here is simple: don't use emberfire!
Basically the entire concept of emberfire is to intergrate firebase into ember-data. If you just want to use some firebase services use the firebase sdk directly.
emberfire uses ember-data under the hood. So you need to have it installed.

How to properly do tree shaking to reduce bundle size and separate entry point for each cloud function

I am using Google Firebase Cloud Functions with TypeScript, and I found out that even though each function is deployed separately, they all share the same bundles and dependencies, even if some functions do not use them nor import them.
In my case, one cloud function uses Redis and others don't. I have 10 functions. All 10 functions actually end up importing redis related code even though they don't import them.
Since all functions share the same entry point, index.js. It currently seems it's impossible to have separate tree-shaken bundles / entry points for each function.
This is very inefficient in terms of bundle size / cold start timing / memory / etc. It also means as I have more and more functions, bundle size will grow for all functions together. It's not scalable.
Is there any way to not share the entry point, index.js, and have completely separate bundles by using bundlers like webpack?
You can create a different local Firebase working area (with firebase init) for each function that should deploy in isolation from the others. You will have to instruct the CLI not to overwrite the other functions on deployment using the --only functions:yourFunctionName to deploy it.
Or, you can deploy function using Cloud tools (gcloud) instead of Firebase tools, but you won't be able to use firebase-functions and its TypeScript bindings.
Or, you can lazily load your modules instead of statically loading them at the global scope of your functions, as described in this video.
I don't recommend using webpack. It's not going to be worth your time to get it configured.
You might try better-firebase-functions, which solves this elegantly by automatically lazy loading only the function that is currently invoked by checking the environment variable FUNCTION_NAME - see https://link.medium.com/4g3CJOLXidb

React-Native : Firebase Realtime Database How Can I Get One Data

I have this database.
database
How can i get firstName in React-Native ?
It's simple in your case : use react-native-firebase
import firebase from 'react-native-firebase'
const ref = firebase.database().ref('users/fwDRY...G3');
const name = ref.get({ firstname: 'firstname' });
console.log(name.firstname)
Find yourself helpful from the docs: https://rnfirebase.io/docs/v5.x.x/database/reference/database
As React Native runs in Java Script thread on mobile platforms there are 2 ways to use it.
Using Web SDK, but it might be slower and is not as well integrated to the mobile operating system as native.
Using Native SDK for each platform. Using them manually on 2 platforms would require you to write React Native bindings for both platforms. Fortunately, the job has already been done. I highly recommend you to use this library https://github.com/invertase/react-native-firebase. It uses native APIs internally but exposes them into nice JavaScript API. It requires some setup but you won't work it around anyway regardless of the method chosen.
For example, to set it up for Android, you need to follow
https://rnfirebase.io/docs/v5.x.x/installation/initial-setup
https://rnfirebase.io/docs/v5.x.x/installation/android
https://rnfirebase.io/docs/v5.x.x/database/android
After you set it up, follow the link provided by frank-van-puffelen, https://firebase.google.com/docs/database/web/read-and-write#listen_for_value_events. The API on react-native-firebase is almost the same.

Generating Swagger Docs in Firebase Cloud Functions project

Is it possible to generate Swagger Spec file from function comments in firebase cloud functions? If so, how can we do it?
I see the cloud functions code to be more like serverless, so wondering if this is possible.
I haven't found an automatic way, but there are plenty of libraries to choose from.
I'm using express and nodejs in my Firebase Function implementations, and for me,
Swagger doc generation can be implemented via the following libraries:
https://github.com/scottie1984/swagger-ui-express
https://github.com/Surnet/swagger-jsdoc
You can find other libraries at:
https://swagger.io/tools/open-source/open-source-integrations/
This will create a new HTTP endpoint, which will serve an HTML page of a swagger doc.
There is not an automatic way to do this at this time. I think you could build your own but seems like it would be a lot of work.

Does using Firestore require the firebase-firestore.js file?

I am using Firebase in my project, including Firestore.
The docs say when setting up Firestore to include firebase-firestore.js in addition to the normal firebase.js file.
Is this required? I included it, but am also looking to reduce dependencies whenever possible.
Yes, it's required. firebase.js contains common code for all Firebase products you might use.

Resources