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

Method initAsync

modules/core/ValidationSystem.js:68–123  ·  view source on GitHub ↗

* initAsync * Called after all core objects have been constructed. * @return {Promise} Promise resolved when this component has completed initialization

()

Source from the content-addressed store, hash-verified

66 * @return {Promise} Promise resolved when this component has completed initialization
67 */
68 initAsync() {
69 if (this._initPromise) return this._initPromise;
70
71 for (const id of this.dependencies) {
72 if (!this.context.systems[id]) {
73 return Promise.reject(`Cannot init: ${this.id} requires ${id}`);
74 }
75 }
76
77 // Create the validation rules
78 const context = this.context;
79 Object.values(Validations).forEach(validation => {
80 if (typeof validation !== 'function') return;
81 const fn = validation(context);
82 this._rules.set(fn.type, fn);
83 });
84
85 // Init prerequisites
86 const editor = context.systems.editor;
87 const storage = context.systems.storage;
88 const urlhash = context.systems.urlhash;
89 const prerequisites = Promise.all([
90 editor.initAsync(),
91 storage.initAsync(),
92 urlhash.initAsync()
93 ]);
94
95 return this._initPromise = prerequisites
96 .then(() => {
97 // Allow validation severity to be overridden by url queryparams...
98 // See: https://github.com/openstreetmap/iD/pull/8243
99 //
100 // Each param should contain a urlencoded comma separated list of
101 // `type/subtype` rules. `*` may be used as a wildcard..
102 // Examples:
103 // `validationError=disconnected_way/*`
104 // `validationError=disconnected_way/highway`
105 // `validationError=crossing_ways/bridge*`
106 // `validationError=crossing_ways/bridge*,crossing_ways/tunnel*`
107 this._errorOverrides = this._parseHashParam(urlhash.initialHashParams.get('validationError'));
108 this._warningOverrides = this._parseHashParam(urlhash.initialHashParams.get('validationWarning'));
109 this._disableOverrides = this._parseHashParam(urlhash.initialHashParams.get('validationDisable'));
110
111 const disabledRules = storage.getItem('validate-disabledRules');
112 if (disabledRules) {
113 const ruleIDs = disabledRules.split(',').map(s => s.trim()).filter(Boolean);
114 this._disabledRuleIDs = new Set(ruleIDs);
115 }
116
117 // Setup event handlers..
118 // When to run validation:
119 editor
120 .on('stablechange', () => this.validateAsync())
121 .on('merge', entityIDs => this._validateBaseEntitiesAsync(entityIDs));
122 });
123 }
124
125

Callers

nothing calls this directly

Calls 10

_parseHashParamMethod · 0.95
validateAsyncMethod · 0.95
valuesMethod · 0.80
getMethod · 0.80
filterMethod · 0.80
splitMethod · 0.80
validationFunction · 0.50
getItemMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected