Nativescript-plugin-firebase: Call init for every module?

Created on 2 Feb 2016  路  1Comment  路  Source: EddyVerbruggen/nativescript-plugin-firebase

In a scenario where the plugin will be used in many views (many view modules) the plugin has to initialize for each module where it is included, isn't that right?

File firebase-common.js line 26 has this:

var firebase = {};
// ...
firebase.instance = null;

But this firebase.instance variable is not used anywhere in the code. Initialization for android has the following code for line 90:

firebase.init = function (arg) {
  return new Promise(function (resolve, reject) {
    try {
      var Firebase = com.firebase.client.Firebase;
      Firebase.setAndroidContext(appModule.android.context);
      instance = new Firebase(arg.url);
      resolve(instance);
    } catch (ex) {
      console.log("Error in firebase.init: " + ex);
      reject(ex);
    }
  });
};

Therefore line 90 creates a new varible called instance and pass it to the resolve() function of the promise.

Is this the expected behavior? A user really has to init the firebase plugin for every module where it will be used? I assumed the firebase.instance variable would be a module cached reference to the first initialization and that every module would use the same instance.

Most helpful comment

I ended up doing a
var firebase = require("nativescript-plugin-firebase");
in my app.js file.

Then in the onApplicationLaunch event, I do the init. From here, I think the firebase variable is cached throughout the app and is globally available and you can just call firebase.whatever. I've been able to perform sets and pushes from various pages, but I'll be testing to make sure that things work throughout.

>All comments

I ended up doing a
var firebase = require("nativescript-plugin-firebase");
in my app.js file.

Then in the onApplicationLaunch event, I do the init. From here, I think the firebase variable is cached throughout the app and is globally available and you can just call firebase.whatever. I've been able to perform sets and pushes from various pages, but I'll be testing to make sure that things work throughout.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thunder413 picture thunder413  路  3Comments

phatakrajan picture phatakrajan  路  4Comments

tsili852 picture tsili852  路  3Comments

yencolon picture yencolon  路  4Comments

dopefatimah picture dopefatimah  路  3Comments