* initAsync * Called after all core objects have been constructed. * @return {Promise} Promise resolved when this component has completed initialization
()
| 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 |
nothing calls this directly
no test coverage detected