Ember fire not synchronizing properly when clearing an array (Cross-post from StackOverflow)

17 views
Skip to first unread message

Matt Mazzola

unread,
May 4, 2016, 2:09:44 AM5/4/16
to Firebase + EmberJS
See original post: http://stackoverflow.com/questions/36908038/ember-fire-not-synchronizing-properly-when-clearing-an-array

The docs say they monitor stackoverflow, but it wasn't getting many views so I'm duplicating it here, since this place looks much more active.

-----

I am storing an array of objects in firebase and using the push method from the server as seen below:

  firebaseRef.child('colors').push(body, (error) => {
    if(error) {
      res.send(500, error);
    }
    else {
      res.send(200);
    }

    return next();
  });

And on the client I am using:

model() {
  return this.store.findAll('color');
}

I have an operation where I want to clear the array and I'm currently using set([]) as seen below:

firebaseRef.child('colors').set([], (error) => { ... });

If I look at the data from the management portal I can see the colors node and all elements are removed; however, the ember client still shows all the items in the array. Even after I add an item to the array to make it a length 1 it would still show perhaps 24 if it had 23 previously. It is only after I completely refresh the client does it properly recognize the length of the array.


How do I reset the array in a way which the client stays synchronized without having to remove each element one by one?



Tim Stirrat

unread,
May 10, 2016, 9:58:18 PM5/10/16
to Matt Mazzola, Firebase + EmberJS
Hi Matt,

Try using this:

store.unloadAll('color');
firebaseRef.child('colors').set(null, (error) => { ... });


Let me know if you have better success with that. Basically, there is a value watcher on each record, plus a watcher on the top level collection. Each record is trying to unload itself, and some might be getting into a bad state. Doing it pre-emptively should help.

Cheers,

Tim


--
You received this message because you are subscribed to the Google Groups "Firebase + EmberJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-embe...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages