question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

return a listener+path from firebase._addObservers

See original GitHub issue

Hi Eddy, i want to propose you some little changes so we can use the removeEventListener

first we return an object with path and listener from the _addObservers

firebase._addObservers = function(to, updateCallback) {
   var listener = new com.google.firebase.database.ChildEventListener({
   [...]
   return listenerPlusPathObj;
}

and we resolve the promise with it

firebase.addChildEventListener = function (updateCallback, path) {
   [...]
   var listenerPlusPathObj = firebase._addObservers(firebase.instance.child(path), updateCallback);
   resolve(listenerPlusPathObj);
   [...]
}

we return the same obj here

firebase.addValueEventListener = function (updateCallback, path) {
   [...]
   resolve(listenerPlusPathObj);
   [...]
}

and then again we resolve the promise with the obj

firebase.query = function (updateCallback, path, options) {
   [...]
   else {
        var listenerPlusPathObj = firebase._addObservers(query, updateCallback);
        resolve(listenerPlusPathObj);
    }
   [...]
}

of course in the query we don’t have to think about the singleEvent option because that listener should die after the first call.

I imagine the listenerPlusPathObj like

{
  "listener": listener,
  "path": path
}

in this way we can call removeEventListener(obj.listener, obj.path);

now we have all the tools to use the firebase.removeEventListener = function (listener, path) which is also very useful for my porting of geofire as a garbage collector for all the unused listeners. what do you think? any problems or better ideas?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
EddyVerbruggencommented, Sep 13, 2016

Btw that NativeScript-Android issue has been fixed and the kind folks at NativeScript will ship the fix with the next release. So we made the framework better with this feature as well 👍

1reaction
andrew19881123commented, Sep 10, 2016

Hi, that’s a great work! I’ve reviewed the code just now (not tested yet) and just one thing came to mind: because the query() returns 1 or 4 listeners depending on the platform and one goal of this plugin is to create a layer of abstraction above the two, in this situation a developer has to understand the problem and use properly the two in the correct case, like removeEventListeners against the query() function (that’s not obvious). So my idea is to hide from the public api the removeEventListener and just give the developer the option to use removeEventListeners which takes an array of listeners (even an array with one element). In this way it’s not confusing, because you can choose only between one option, and you keep the same functionality…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get realtime updates with Cloud Firestore - Firebase
In JavaScript, use the Promise returned from your write operation by attaching a .then() callback. In Swift, pass a completion callback to your...
Read more >
Firebase database doesn't return data - Stack Overflow
I am currently trying to make an account page for users using data from Firebase auth, database, and storage. The only problem with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found