Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Call init for every module? #11

Closed
afortaleza opened this issue Feb 2, 2016 · 1 comment
Closed

Call init for every module? #11

afortaleza opened this issue Feb 2, 2016 · 1 comment

Comments

@afortaleza
Copy link

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.

@afortaleza afortaleza changed the title New instance in every module? Call init for every module? Feb 2, 2016
@Lampei
Copy link
Contributor

Lampei commented Mar 12, 2016

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.

ngocnt1 added a commit to ngocnt1/nativescript-plugin-firebase that referenced this issue Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants