@hkdigital/lib-core 0.4.80 → 0.4.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -29,16 +29,10 @@ const MAX_TIMEOUT_MS = 120000;
|
|
|
29
29
|
export default class SceneBase {
|
|
30
30
|
#state = new LoadingStateMachine();
|
|
31
31
|
|
|
32
|
-
// @note this exported state is set by
|
|
32
|
+
// @note this exported state is set by #setState
|
|
33
33
|
state = $state(STATE_INITIAL);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return this.state === STATE_INITIAL;
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
loaded = $derived.by(() => {
|
|
40
|
-
return this.state === STATE_LOADED;
|
|
41
|
-
});
|
|
34
|
+
initial = $state(true);
|
|
35
|
+
loaded = $state(false);
|
|
42
36
|
|
|
43
37
|
// aborted = $derived.by(() => {
|
|
44
38
|
// return this.state === STATE_ABORTED;
|
|
@@ -94,12 +88,23 @@ export default class SceneBase {
|
|
|
94
88
|
};
|
|
95
89
|
});
|
|
96
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Internal state setter that updates all related state properties
|
|
93
|
+
*
|
|
94
|
+
* @param {string} newState - The new state value
|
|
95
|
+
*/
|
|
96
|
+
#setState(newState) {
|
|
97
|
+
this.state = newState;
|
|
98
|
+
this.initial = newState === STATE_INITIAL;
|
|
99
|
+
this.loaded = newState === STATE_LOADED;
|
|
100
|
+
}
|
|
101
|
+
|
|
97
102
|
/**
|
|
98
103
|
* Construct SceneBase
|
|
99
104
|
*/
|
|
100
105
|
constructor() {
|
|
101
106
|
this.#state.onenter = (currentState) => {
|
|
102
|
-
console.debug('SceneBase:onenter', currentState);
|
|
107
|
+
// console.debug('SceneBase:onenter', currentState);
|
|
103
108
|
|
|
104
109
|
if (currentState === STATE_LOADING) {
|
|
105
110
|
this.#startLoading();
|
|
@@ -107,14 +112,14 @@ export default class SceneBase {
|
|
|
107
112
|
this.#startAbort();
|
|
108
113
|
}
|
|
109
114
|
|
|
110
|
-
this
|
|
115
|
+
this.#setState(currentState);
|
|
111
116
|
};
|
|
112
117
|
|
|
113
118
|
$effect(() => {
|
|
114
119
|
if (this.state === STATE_LOADING) {
|
|
115
120
|
const { sourcesLoaded, numberOfSources } = this.progress;
|
|
116
121
|
|
|
117
|
-
console.debug( 'SceneBase:check-for-loaded', {sourcesLoaded, numberOfSources} );
|
|
122
|
+
// console.debug( 'SceneBase:check-for-loaded', {sourcesLoaded, numberOfSources} );
|
|
118
123
|
|
|
119
124
|
if (sourcesLoaded === numberOfSources) {
|
|
120
125
|
this.#state.send(LOADED);
|
|
@@ -287,16 +292,16 @@ export default class SceneBase {
|
|
|
287
292
|
// 0 means no timeout, but actually we use max timeout
|
|
288
293
|
const waitTimeout = timeoutMs > 0 ? timeoutMs : MAX_TIMEOUT_MS;
|
|
289
294
|
|
|
290
|
-
console.debug('SceneBase:waitForState:currentState', this.state);
|
|
295
|
+
// console.debug('SceneBase:waitForState:currentState', this.state);
|
|
291
296
|
|
|
292
297
|
waitForState(() => {
|
|
293
298
|
const ready = (
|
|
294
|
-
this.
|
|
299
|
+
this.loaded ||
|
|
295
300
|
this.state === STATE_ABORTED ||
|
|
296
301
|
this.state === STATE_ERROR
|
|
297
302
|
);
|
|
298
303
|
|
|
299
|
-
console.debug( { loaded: this.loaded, state: this.state, ready } );
|
|
304
|
+
// console.debug( { loaded: this.loaded, state: this.state, ready } );
|
|
300
305
|
|
|
301
306
|
return ready;
|
|
302
307
|
}, waitTimeout)
|
|
@@ -393,7 +398,7 @@ export default class SceneBase {
|
|
|
393
398
|
const loader = this.getLoaderFromSource(source);
|
|
394
399
|
|
|
395
400
|
loader.load((completedLoader, finalState) => {
|
|
396
|
-
console.debug(`SceneBase:loader-finished [${completedLoader._url}] ${finalState}`);
|
|
401
|
+
// console.debug(`SceneBase:loader-finished [${completedLoader._url}] ${finalState}`);
|
|
397
402
|
|
|
398
403
|
// Check for errors
|
|
399
404
|
if (finalState === STATE_ERROR) {
|
|
@@ -404,18 +409,18 @@ export default class SceneBase {
|
|
|
404
409
|
// Check for abort - don't count aborted loaders as completed
|
|
405
410
|
if (finalState === STATE_ABORTED) {
|
|
406
411
|
// Aborted loaders are handled by SceneBase's own abort logic
|
|
407
|
-
console.debug(`SceneBase:loader-aborted [${completedLoader._url}] - not counting toward completion`);
|
|
412
|
+
// console.debug(`SceneBase:loader-aborted [${completedLoader._url}] - not counting toward completion`);
|
|
408
413
|
return;
|
|
409
414
|
}
|
|
410
415
|
|
|
411
416
|
// Only count successfully loaded loaders
|
|
412
417
|
if (finalState === STATE_LOADED) {
|
|
413
418
|
completedCount++;
|
|
414
|
-
console.debug(`SceneBase:loader-completed [${completedLoader._url}] (${completedCount}/${totalLoaders})`);
|
|
419
|
+
// console.debug(`SceneBase:loader-completed [${completedLoader._url}] (${completedCount}/${totalLoaders})`);
|
|
415
420
|
|
|
416
421
|
// Check for completion
|
|
417
422
|
if (completedCount === totalLoaders) {
|
|
418
|
-
console.debug('SceneBase:all-loaders-completed-via-callback');
|
|
423
|
+
// console.debug('SceneBase:all-loaders-completed-via-callback');
|
|
419
424
|
this.#state.send(LOADED);
|
|
420
425
|
}
|
|
421
426
|
}
|
|
@@ -106,7 +106,7 @@ export default class NetworkLoader {
|
|
|
106
106
|
this._url = url;
|
|
107
107
|
|
|
108
108
|
this.#state.onenter = (currentState) => {
|
|
109
|
-
console.debug(`loader:onenter [${this._url}] ${currentState}`);
|
|
109
|
+
// console.debug(`loader:onenter [${this._url}] ${currentState}`);
|
|
110
110
|
this.state = currentState;
|
|
111
111
|
|
|
112
112
|
// Check if we've reached a terminal state
|
|
@@ -328,7 +328,7 @@ export default class NetworkLoader {
|
|
|
328
328
|
const { bufferPromise, abort: abortLoadBody } = loadResponseBuffer(
|
|
329
329
|
response,
|
|
330
330
|
({ bytesLoaded, size }) => {
|
|
331
|
-
console.debug(`loader:progress [${this._url}] ${bytesLoaded}/${size} bytes`);
|
|
331
|
+
// console.debug(`loader:progress [${this._url}] ${bytesLoaded}/${size} bytes`);
|
|
332
332
|
this._bytesLoaded = bytesLoaded;
|
|
333
333
|
this._size = size;
|
|
334
334
|
}
|
|
@@ -349,11 +349,11 @@ export default class NetworkLoader {
|
|
|
349
349
|
|
|
350
350
|
// Check if we've been aborted before sending LOADED
|
|
351
351
|
if (this.#state.current === STATE_ABORTING || this.#state.current === STATE_ABORTED) {
|
|
352
|
-
console.debug(`loader:already-aborted [${this._url}] - not sending LOADED`);
|
|
352
|
+
// console.debug(`loader:already-aborted [${this._url}] - not sending LOADED`);
|
|
353
353
|
return;
|
|
354
354
|
}
|
|
355
355
|
|
|
356
|
-
console.debug(`loader:sending-LOADED [${this._url}]`);
|
|
356
|
+
// console.debug(`loader:sending-LOADED [${this._url}]`);
|
|
357
357
|
this.#state.send(LOADED);
|
|
358
358
|
} catch (e) {
|
|
359
359
|
this.#state.send(ERROR, e);
|