Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 35935c7

Browse files
committed
feat(Layer): add startup lifecycle method
1 parent f740b72 commit 35935c7

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

packages/Main/src/Core/View.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,7 @@ class View extends THREE.EventDispatcher {
374374
this.scene.add(layer.object3d);
375375
}
376376

377-
Promise.all(layer._promises).then(() => {
378-
layer._resolve();
377+
layer.startup().then(() => {
379378
this.notifyChange(parentLayer || layer, false);
380379
if (!this._frameRequesters[MAIN_LOOP_EVENTS.UPDATE_END] ||
381380
!this._frameRequesters[MAIN_LOOP_EVENTS.UPDATE_END].includes(this._allLayersAreReadyCallback)) {
@@ -385,7 +384,7 @@ class View extends THREE.EventDispatcher {
385384
type: VIEW_EVENTS.LAYER_ADDED,
386385
layerId: layer.id,
387386
});
388-
}, layer._reject);
387+
});
389388

390389
return layer.whenReady;
391390
}

packages/Main/src/Layer/Layer.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,21 @@ class Layer extends THREE.EventDispatcher {
179179
return resolve;
180180
}
181181

182+
/**
183+
* The startup stage is the first stage of the layer lifecycle. It is called
184+
* internally when the layer is added to the view.
185+
* @param {View} context - the context the layer has been added to.
186+
* @returns {Promise<void>}
187+
*/
188+
async startup(/* context */) {
189+
try {
190+
await Promise.all(this._promises);
191+
this._resolve();
192+
} catch (error) {
193+
this._reject(error);
194+
}
195+
}
196+
182197
/**
183198
* Defines a property for this layer, with a default value and a callback
184199
* executed when the property changes.

0 commit comments

Comments
 (0)