MCPcopy Create free account
hub / github.com/facebook/Rapid / merge

Method merge

modules/core/EditSystem.js:627–664  ·  view source on GitHub ↗

* merge * Merge new entities into the Base Graph. * This function is called when we have parsed a new tile of OSM data, we will * receive the new entities and a list of all entity ids that the tile contains. * Can also be called in other situations, like restoring history from *

(entities, seenIDs)

Source from the content-addressed store, hash-verified

625 * @param {Set} seenIDs? - Optional set of all entity IDs on the tile (including previously seen ones)
626 */
627 merge(entities, seenIDs) {
628 const baseGraph = this.base.graph;
629 const stagingGraph = this.staging.graph;
630
631 if (!(seenIDs instanceof Set)) {
632 seenIDs = new Set(entities.map(entity => entity.id));
633 }
634
635 // Which ones are really new (not in the Base Graph)?
636 const newIDs = new Set();
637 for (const entity of entities) {
638 if (!baseGraph.hasEntity(entity.id)) { // not merged in yet.
639 newIDs.add(entity.id);
640 }
641 }
642
643 // If we are merging in new relation members, bump the relation's version.
644 for (const id of seenIDs) {
645 const entity = stagingGraph.hasEntity(id);
646 if (entity?.type !== 'relation') continue;
647
648 for (const member of entity.members) {
649 if (newIDs.has(member.id)) {
650 entity.touch(); // bump version in place
651 }
652 }
653 }
654
655 // Append staging graph..
656 // It's not in the history yet, but it represents the current state of things.
657 const graphs = this._history.map(state => state.graph);
658 graphs.push(stagingGraph);
659
660 baseGraph.rebase(entities, graphs, false); // force = false
661 this._tree.rebase(entities, false); // force = false
662
663 this.emit('merge', seenIDs);
664 }
665
666
667 /**

Callers 15

_afterLoadMethod · 0.45
renderMethod · 0.45
renderFunction · 0.45
noteSaveSectionFunction · 0.45
userDetailsFunction · 0.45
noteSaveButtonsFunction · 0.45
uiTagReferenceFunction · 0.45
flashFunction · 0.45
renderFunction · 0.45
renderFunction · 0.45
uiSectionFunction · 0.45
renderMethod · 0.45

Calls 3

hasEntityMethod · 0.80
touchMethod · 0.80
rebaseMethod · 0.45

Tested by 1

prepareTestHistoryFunction · 0.36