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

Method initAsync

modules/core/ImagerySystem.js:60–96  ·  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

58 * @return {Promise} Promise resolved when this component has completed initialization
59 */
60 initAsync() {
61 if (this._initPromise) return this._initPromise;
62
63 for (const id of this.dependencies) {
64 if (!this.context.systems[id]) {
65 return Promise.reject(`Cannot init: ${this.id} requires ${id}`);
66 }
67 }
68
69 const context = this.context;
70 const assets = context.systems.assets;
71 const gfx = context.systems.gfx;
72 const map = context.systems.map;
73 const storage = context.systems.storage;
74 const urlhash = context.systems.urlhash;
75
76 const prerequisites = Promise.all([
77 assets.initAsync(),
78 gfx.initAsync(), // `gfx.scene` will exist after `initAsync`
79 map.initAsync(), // `ImagerySystem` should listen for 'hashchange' after `MapSystem`
80 storage.initAsync(),
81 urlhash.initAsync()
82 ]);
83
84 return this._initPromise = prerequisites
85 .then(() => {
86 // Setup event handlers..
87 urlhash.on('hashchange', this._hashchange);
88 gfx.scene.on('layerchange', this._imageryChanged);
89 })
90 .then(() => assets.loadAssetAsync('imagery'))
91 .then(data => this._initImageryIndex(data))
92 .then(() => this._initWaybackAsync());
93 // .catch(e => {
94 // if (e instanceof Error) console.error(e); // eslint-disable-line no-console
95 // });
96 }
97
98
99 /**

Callers

nothing calls this directly

Calls 4

_initImageryIndexMethod · 0.95
_initWaybackAsyncMethod · 0.95
loadAssetAsyncMethod · 0.80
onMethod · 0.45

Tested by

no test coverage detected