Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let result;
let requestedPathsSoFar = {};
let requestedPathsSoFar_last;
do {
requestedPathsSoFar_last = Clone(requestedPathsSoFar);
ClearRequestedPaths();
result = dbGetterFunc();
let newRequestedPaths = GetRequestedPaths().Except(requestedPathsSoFar.VKeys());
if (!dbDataLocked) {
StartBufferingActions();
//let oldNodeRenderCount = NodeUI.renderCount;
unWatchEvents(firebase, store.dispatch, getEventsFromInput(newRequestedPaths)); // do this just to trigger re-get
// start watching paths (causes paths to be requested)
watchEvents(firebase, store.dispatch, getEventsFromInput(newRequestedPaths));
//Assert(NodeUI.renderCount == oldNodeRenderCount, "NodeUIs rendered during unwatch/watch event!");
StopBufferingActions();
}
for (let path of newRequestedPaths) {
requestedPathsSoFar[path] = true;
// wait till data is received (assuming we don't have a state-override that's just locking the content of firebase.data anyway)
if (!dbDataLocked) {
await WaitTillPathDataIsReceived(path);
}
}
// stop watching paths (since we already got their data)
// todo: find correct way of unwatching events; the way below seems to sometimes unwatch while still needed watched
let requestedPathsSoFar = {};
let requestedPathsSoFar_last;
do {
requestedPathsSoFar_last = Clone(requestedPathsSoFar);
ClearRequestedPaths();
result = dbGetterFunc();
let newRequestedPaths = GetRequestedPaths().Except(requestedPathsSoFar.VKeys());
if (!dbDataLocked) {
StartBufferingActions();
//let oldNodeRenderCount = NodeUI.renderCount;
unWatchEvents(firebase, store.dispatch, getEventsFromInput(newRequestedPaths)); // do this just to trigger re-get
// start watching paths (causes paths to be requested)
watchEvents(firebase, store.dispatch, getEventsFromInput(newRequestedPaths));
//Assert(NodeUI.renderCount == oldNodeRenderCount, "NodeUIs rendered during unwatch/watch event!");
StopBufferingActions();
}
for (let path of newRequestedPaths) {
requestedPathsSoFar[path] = true;
// wait till data is received (assuming we don't have a state-override that's just locking the content of firebase.data anyway)
if (!dbDataLocked) {
await WaitTillPathDataIsReceived(path);
}
}
// stop watching paths (since we already got their data)
// todo: find correct way of unwatching events; the way below seems to sometimes unwatch while still needed watched
// for now, we just never unwatch
//unWatchEvents(firebase, store.dispatch, getEventsFromInput(newRequestedPaths));
setImmediate(()=> {
s._firebaseEvents = getEventsFromInput(requestedPaths);
let removedPaths = oldRequestedPaths.Except(...requestedPaths);
// todo: find correct way of unwatching events; the way below seems to sometimes unwatch while still needed watched
// for now, we just never unwatch
//unWatchEvents(firebase, DispatchDBAction, getEventsFromInput(removedPaths));
let addedPaths = requestedPaths.Except(...oldRequestedPaths);
watchEvents(firebase, DispatchDBAction, getEventsFromInput(addedPaths));
// for debugging, you can check currently-watched-paths using: store.firebase._.watchers
});
s.lastRequestedPaths = requestedPaths;
setImmediate(()=> {
s._firebaseEvents = getEventsFromInput(requestedPaths);
let removedPaths = oldRequestedPaths.Except(...requestedPaths);
// todo: find correct way of unwatching events; the way below seems to sometimes unwatch while still needed watched
// for now, we just never unwatch
//unWatchEvents(firebase, DispatchDBAction, getEventsFromInput(removedPaths));
let addedPaths = requestedPaths.Except(...oldRequestedPaths);
watchEvents(firebase, DispatchDBAction, getEventsFromInput(addedPaths));
// for debugging, you can check currently-watched-paths using: store.firebase._.watchers
});
s.lastRequestedPaths = requestedPaths;