Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child_added triggered with partial data #101

Open
nvdbleek opened this issue Oct 21, 2015 · 0 comments
Open

child_added triggered with partial data #101

nvdbleek opened this issue Oct 21, 2015 · 0 comments

Comments

@nvdbleek
Copy link

The child_added event is triggered with not the complete data tree when you set data on a child that doesn't yet exists (all but the first key of the object is not present yet, and you gat a value event for the rest of the keys). My use case is to use transaction() to make sure that the child is only added when it doesn't yet exists, to make sure that only one client will add the node at that particular key.

If you run the following example:

var Firebase = require('mockfirebase');

var ref = new Firebase.MockFirebase('child_added://');
ref.child('foo').on('child_added', function (snaphot) {
  console.log(snaphot.key() + ' = ' + JSON.stringify(snaphot.val()))
});

ref.child('foo').child('a1').set({ foo: ['baz'], qux: 'norf'} );
ref.flush();

ref.child('foo').child('a2').transaction(function (current) {
   if (current === null) {
     return { foo: ['baz'], qux: 'norf'};
    }
  },
  function (error, committed, snaphot) {
    // console.log(snaphot.key() + ' = ' + JSON.stringify(snaphot.val()))
});
ref.flush();

You get the following output:

a1 = {"foo":{"0":"baz"}}
a2 = {"foo":{"0":"baz"}}

I would have expected to get:

a1 = {"foo":["baz"],"qux":"norf"}
a2 = {"foo":["baz"],"qux":"norf"}

Note the missing qux key in the output.

I tried to delay the sending of the child_added event, because it is send after that the first entry is added. But my attempt breaks a lot of other tests.

Is it possible to point me in the correct direction to make a fix for this issue.

My attempt is pushed as commit nvdbleek@9c1f099

Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant