How to use the @firebase/util.map function in @firebase/util

To help you get started, we’ve selected a few @firebase/util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github firebase / firebase-js-sdk / packages / database / src / core / Repo.ts View on Github external
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) {
github firebase / firebase-js-sdk / packages / database / src / core / Repo.ts View on Github external
);
        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);
  }
github firebase / firebase-js-sdk / packages / database / src / core / Repo.ts View on Github external
);
        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);
  }
github firebase / firebase-js-sdk / packages / database / src / core / snap / IndexMap.ts View on Github external
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;
          }
        }
github firebase / firebase-js-sdk / packages / database / src / core / snap / IndexMap.ts View on Github external
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();
github firebase / firebase-js-sdk / packages / database / src / core / Repo.ts View on Github external
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) {