Per this question Why do my Firebase 'child_added' events show up out-of-order? it seems that Firebase makes no garauntees about all clients seeing additions to a list in the same order. Is there some way to force Firebase to use strict ordering and only see local events once they have been confirmed by the server?
Asked
Active
Viewed 124 times
0
-
Is there a problem with using the approach documented in the link you referenced? Using prevId to decide where to put the incoming records? It's perfectly guaranteed to be the right order. – Kato Apr 03 '14 at 23:03
-
The solutions presented do not have an equivalent outcome. In my application the children are not a list of items, but a list of transformations to apply. If I apply "C" before "B" I would need an entire operational transform algorithm in order to patch it up when "B" arrives, because the state of the current system is not the state the "B" was expecting. – lemiant Apr 04 '14 at 13:30
-
Which is why getting the items only when confirmed by the server would be much much easier – lemiant Apr 04 '14 at 13:31
1 Answers
0
The items could appear out of order because it's a real-time distributed system. If multiple records arrive to the server, their keys or priorities could cause them to be inserted before a record that has already been added. Multiply this by 100 users all working in data that is at a different state on their local machine, and it makes sense that ordering is fluid as things move or shift in the list.
However, you can obtain a "snapshot" of the data using the value
event, and iterate the items in order using forEach to guarantee the order.
var fb = new Firebase(URL);
// obtain a snapshot of data
fb.once('value', function(snap) {
// iterate the values in order
snap.forEach(function(childSnap) {
console.log(childSnap.name(), childSnap.getPriority(), childSnap.val());
});
});

Kato
- 40,352
- 6
- 119
- 149