Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Value callbacks always triggered with null first #2

Closed
ginovva320 opened this issue Jun 7, 2015 · 5 comments
Closed

Value callbacks always triggered with null first #2

ginovva320 opened this issue Jun 7, 2015 · 5 comments

Comments

@ginovva320
Copy link

If I listen for the value event on a node, the snapshot that's returned contains no data on the first event. So if I'm using once, the value is null. But if I use on, the callback is called twice, once with null and once again with the data.

var FirebaseServer = require('firebase-server');

var s = new FirebaseServer(5000, 'dummy.firebaseio.test', {
    states: {
        CA: 'California',
        AL: 'Alabama',
        KY: 'Kentucky'
    }
});

var Firebase = require('firebase');

var client = new Firebase('ws://dummy.firebaseio.test:5000');

client.child('states').child('CA').on('value', function(snap) {
    console.log('Value: ' + snap.val());
});

Output:

Value: null
Value: California
@urish
Copy link
Owner

urish commented Jun 12, 2015

Thanks for reporting, I could successfully reproduce the issue. Any idea what is causing this?

@ginovva320
Copy link
Author

I don't know much about Firebase's internals, but my guess would be that the initial null is what's stored locally before a sync occurs. This sort of thing happens during a transaction normally, but in that case, the SDK "knows" to run the transaction function again until data is synced with the server.

@urish urish closed this as completed in f329c35 Jun 12, 2015
@urish
Copy link
Owner

urish commented Jun 13, 2015

Just pushed a fix - can you please try it and let me know if it solves the problems?

Once the solution will be verified, I will release it as 0.2.0.

Thanks!

@ginovva320
Copy link
Author

The value callbacks are working as expected now. Thanks for the quick fix!

@urish
Copy link
Owner

urish commented Jun 13, 2015

Great news! Released to npm as v0.2.0

yingray pushed a commit to yingray/firebase-server that referenced this issue Mar 30, 2019
update package.json for publishing
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

2 participants