Closed brandonmp closed 8 years ago
actually maybe something like this would let users pick their own events by declaring an action creator for it. what do you think? I also added value
event, was ther a reason for not including that?
const EVENT_TYPES = ['child_added', 'child_removed', 'value', 'child_changed', 'child_moved'];
export function* sync(path, mapEventToAction = {}, limit = 20) {
const ref = typeof limit === 'number' ?
firebase.database().ref(path).limitToLast(limit)
: firebase.database().ref(path)
let eventTypes = Object.keys(mapEventToAction)
for (let type of eventTypes) {
// make sure event types are valid
if (EVENT_TYPES.indexOf(type) === -1) break;
const action = mapEventToAction[type];
if (typeof action === 'function') {
yield fork(runSync, ref, type, action);
}
}
}
Hey @brandonmp,
Thanks for your suggestions, and I have made the following changes in response:
limit
in sync
value
to the EVNET_TYPES
Sync
now covers all eventstransform-runtime
as it was giving issues when installing packages. This needs to be revisited
two questions on this code:
limit
? i would assume the default use case would be no limit. would this be more general?const EVENT_TYPES = ['child_added', 'child_removed'];
is that a bug or is it meant to only cover add/remove?
i can submit prs for this stuff, just let me know !