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

Method merge

modules/core/PresetSystem.js:147–262  ·  view source on GitHub ↗

* merge * Accepts an object containing new preset data (all properties optional): * { * fields: {}, // fieldID -> fieldData * presets: {}, // presetID -> presetData * categories: {}, // categoryID -> categoryData * defaults: {},

(src)

Source from the content-addressed store, hash-verified

145 * }
146 */
147 merge(src) {
148 let newLocationSets = [];
149 const context = this.context;
150 const locations = context.systems.locations;
151
152 // Merge Fields
153 if (src.fields) {
154 for (const [fieldID, f] of Object.entries(src.fields)) {
155 if (f) { // add or replace
156 if (!uiFields[f.type]) {
157 if (VERBOSE) console.warn(`"${f.type}" type not supported for ${fieldID}`); // eslint-disable-line no-console
158 continue;
159 }
160 const field = new Field(context, fieldID, f, this._fields);
161 if (field.locationSet) newLocationSets.push(field);
162 this._fields[fieldID] = field;
163
164 } else { // remove
165 delete this._fields[fieldID];
166 }
167 }
168 }
169
170 // Merge Presets
171 if (src.presets) {
172 for (const [presetID, p] of Object.entries(src.presets)) {
173 const existing = this._presets[presetID];
174 const isFallback = existing?.isFallback();
175
176 if (p) { // add or replace
177
178// Rename icon identifiers to match the rapid spritesheet
179if (p.icon) p.icon = p.icon.replace(/^iD-/, 'rapid-');
180
181// A few overrides to use better icons than the ones provided by the id-tagging-schema project
182if (presetID === 'address') p.icon = 'maki-circle-stroked';
183if (presetID === 'highway/turning_loop') p.icon = 'maki-circle';
184//if (/^highway\/crossing/.test(presetID)) p.icon = 'temaki-pedestrian';
185//if (/^highway\/footway\/crossing/.test(presetID)) p.icon = 'temaki-pedestrian';
186if (p.icon === 'roentgen-needleleaved_tree') p.icon = 'temaki-tree_needleleaved';
187if (p.icon === 'roentgen-tree') p.icon = 'temaki-tree_broadleaved';
188
189 const preset = new Preset(context, presetID, p, this._fields, this._presets);
190 if (preset.locationSet) newLocationSets.push(preset);
191 this._presets[presetID] = preset;
192
193 } else if (!isFallback) { // remove (but not if it's a fallback)
194 delete this._presets[presetID];
195 }
196 }
197 }
198
199 // Merge Categories
200 if (src.categories) {
201 for (const [categoryID, c] of Object.entries(src.categories)) {
202 if (c) { // add or replace
203// Rename icon identifiers to match the rapid spritesheet
204if (c.icon) c.icon = c.icon.replace(/^iD-/, 'rapid-');

Callers 1

initAsyncMethod · 0.95

Calls 7

resetFieldsMethod · 0.95
replaceMethod · 0.80
filterMethod · 0.80
valuesMethod · 0.80
mergeCustomGeoJSONMethod · 0.80
mergeLocationSetsMethod · 0.80
isFallbackMethod · 0.45

Tested by

no test coverage detected