Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private onDataUpdate_(
pathString: string,
data: any,
isMerge: boolean,
tag: number | null
) {
// For testing.
this.dataUpdateCount++;
const path = new Path(pathString);
data = this.interceptServerDataCallback_
? this.interceptServerDataCallback_(pathString, data)
: data;
let events = [];
if (tag) {
if (isMerge) {
const taggedChildren = map(data as { [k: string]: any }, (raw: any) =>
nodeFromJSON(raw)
);
events = this.serverSyncTree_.applyTaggedQueryMerge(
path,
taggedChildren,
tag
);
} else {
const taggedSnap = nodeFromJSON(data);
events = this.serverSyncTree_.applyTaggedQueryOverwrite(
path,
taggedSnap,
tag
);
}
} else if (isMerge) {
);
events = this.serverSyncTree_.applyTaggedQueryMerge(
path,
taggedChildren,
tag
);
} else {
const taggedSnap = nodeFromJSON(data);
events = this.serverSyncTree_.applyTaggedQueryOverwrite(
path,
taggedSnap,
tag
);
}
} else if (isMerge) {
const changedChildren = map(data as { [k: string]: any }, (raw: any) =>
nodeFromJSON(raw)
);
events = this.serverSyncTree_.applyServerMerge(path, changedChildren);
} else {
const snap = nodeFromJSON(data);
events = this.serverSyncTree_.applyServerOverwrite(path, snap);
}
let affectedPath = path;
if (events.length > 0) {
// Since we have a listener outstanding for each transaction, receiving any events
// is a proxy for some change having occurred.
affectedPath = this.rerunTransactions_(path);
}
this.eventQueue_.raiseEventsForChangedPath(affectedPath, events);
}
);
events = this.serverSyncTree_.applyTaggedQueryMerge(
path,
taggedChildren,
tag
);
} else {
const taggedSnap = nodeFromJSON(data);
events = this.serverSyncTree_.applyTaggedQueryOverwrite(
path,
taggedSnap,
tag
);
}
} else if (isMerge) {
const changedChildren = map(data as { [k: string]: any }, (raw: any) =>
nodeFromJSON(raw)
);
events = this.serverSyncTree_.applyServerMerge(path, changedChildren);
} else {
const snap = nodeFromJSON(data);
events = this.serverSyncTree_.applyServerOverwrite(path, snap);
}
let affectedPath = path;
if (events.length > 0) {
// Since we have a listener outstanding for each transaction, receiving any events
// is a proxy for some change having occurred.
affectedPath = this.rerunTransactions_(path);
}
this.eventQueue_.raiseEventsForChangedPath(affectedPath, events);
}
removeFromIndexes(
namedNode: NamedNode,
existingChildren: SortedMap
): IndexMap {
const newIndexes = map(
this.indexes_,
(indexedChildren: SortedMap) => {
if (indexedChildren === fallbackObject) {
// This is the fallback. Just return it, nothing to do in this case
return indexedChildren;
} else {
const existingSnap = existingChildren.get(namedNode.name);
if (existingSnap) {
return indexedChildren.remove(
new NamedNode(namedNode.name, existingSnap)
);
} else {
// No record of this child
return indexedChildren;
}
}
addToIndexes(
namedNode: NamedNode,
existingChildren: SortedMap
): IndexMap {
const newIndexes = map(
this.indexes_,
(indexedChildren: SortedMap, indexName: string) => {
const index = safeGet(this.indexSet_, indexName);
assert(index, 'Missing index implementation for ' + indexName);
if (indexedChildren === fallbackObject) {
// Check to see if we need to index everything
if (index.isDefinedOn(namedNode.node)) {
// We need to build this index
const childList = [];
const iter = existingChildren.getIterator(NamedNode.Wrap);
let next = iter.getNext();
while (next) {
if (next.name !== namedNode.name) {
childList.push(next);
}
next = iter.getNext();
private onDataUpdate_(
pathString: string,
data: any,
isMerge: boolean,
tag: number | null
) {
// For testing.
this.dataUpdateCount++;
const path = new Path(pathString);
data = this.interceptServerDataCallback_
? this.interceptServerDataCallback_(pathString, data)
: data;
let events = [];
if (tag) {
if (isMerge) {
const taggedChildren = map(data as { [k: string]: any }, (raw: any) =>
nodeFromJSON(raw)
);
events = this.serverSyncTree_.applyTaggedQueryMerge(
path,
taggedChildren,
tag
);
} else {
const taggedSnap = nodeFromJSON(data);
events = this.serverSyncTree_.applyTaggedQueryOverwrite(
path,
taggedSnap,
tag
);
}
} else if (isMerge) {