javascript - How can I know when a Firebase query has ended -
i want collect recent 10 items datastore. believe supposed using .child()
, .limittolast()
, emits event every time result has been added child.
i don't know if there 10 items in total, simple counter won't work.
how know when firebase finished giving me results?
example lookup code:
var plots = []; firebasedatastore.child("plots").orderbychild("unicode-timestamp").limittolast(10).on("child_added", function(snapshot) { // add new item list plots.push(snapshot.val()); });
i need know when final plot has been added, regardless of whether has hit limit.
a firebase query never ends. continues monitor (in case) plots unicode-timestamp , keep "window" of last 10 plots.
so:
- child_added:timestamp1
- child_added:timestamp2
- ...
- child_added:timestamp9
- child_added:timestamp10
and when add plot:
- child_removed:timestamp1
- child_added:timestamp11
if not looking use behavior, have 2 options:
- use
value
event ,snapshot.foreach
on child nodes - keep counter ,
off
listener when you've reached number of children expect
Comments
Post a Comment