@hkdigital/lib-core 0.5.51 → 0.5.52
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.
|
@@ -111,20 +111,13 @@ export default class PageMachine {
|
|
|
111
111
|
* Synchronize machine state with URL path
|
|
112
112
|
*
|
|
113
113
|
* Call this in a $effect that watches $page.url.pathname
|
|
114
|
-
* Automatically tracks visited states
|
|
114
|
+
* Automatically tracks visited states and triggers onEnter hooks
|
|
115
115
|
*
|
|
116
116
|
* @param {string} currentPath - Current URL pathname
|
|
117
117
|
*
|
|
118
118
|
* @returns {boolean} True if state was changed
|
|
119
119
|
*/
|
|
120
120
|
syncFromPath(currentPath: string): boolean;
|
|
121
|
-
/**
|
|
122
|
-
* Set the current state directly
|
|
123
|
-
* Handles onEnter hooks and auto-transitions
|
|
124
|
-
*
|
|
125
|
-
* @param {string} newState - Target state
|
|
126
|
-
*/
|
|
127
|
-
setState(newState: string): Promise<void>;
|
|
128
121
|
/**
|
|
129
122
|
* Get route path for a given state
|
|
130
123
|
*
|
|
@@ -241,7 +241,7 @@ export default class PageMachine {
|
|
|
241
241
|
* Synchronize machine state with URL path
|
|
242
242
|
*
|
|
243
243
|
* Call this in a $effect that watches $page.url.pathname
|
|
244
|
-
* Automatically tracks visited states
|
|
244
|
+
* Automatically tracks visited states and triggers onEnter hooks
|
|
245
245
|
*
|
|
246
246
|
* @param {string} currentPath - Current URL pathname
|
|
247
247
|
*
|
|
@@ -251,14 +251,12 @@ export default class PageMachine {
|
|
|
251
251
|
const targetState = this.#getStateFromPath(currentPath);
|
|
252
252
|
|
|
253
253
|
if (targetState && targetState !== this.#current) {
|
|
254
|
-
// const oldState = this.#current;
|
|
255
|
-
this.#current = targetState;
|
|
256
|
-
this.#visitedStates.add(targetState);
|
|
257
|
-
this.#revision++;
|
|
258
|
-
|
|
259
254
|
// Log state transition from URL sync
|
|
260
255
|
this.logger?.debug(`syncFromPath: ${currentPath} → targetState: ${targetState}`);
|
|
261
256
|
|
|
257
|
+
// Use #setState to handle onEnter hooks
|
|
258
|
+
this.#setState(targetState);
|
|
259
|
+
|
|
262
260
|
return true;
|
|
263
261
|
}
|
|
264
262
|
|
|
@@ -266,12 +264,16 @@ export default class PageMachine {
|
|
|
266
264
|
}
|
|
267
265
|
|
|
268
266
|
/**
|
|
269
|
-
* Set the current state directly
|
|
267
|
+
* Set the current state directly (internal use only)
|
|
270
268
|
* Handles onEnter hooks and auto-transitions
|
|
271
269
|
*
|
|
270
|
+
* Note: This is private to enforce URL-first navigation.
|
|
271
|
+
* To change state, navigate to the URL using switchToPage()
|
|
272
|
+
* and let syncFromPath() update the state.
|
|
273
|
+
*
|
|
272
274
|
* @param {string} newState - Target state
|
|
273
275
|
*/
|
|
274
|
-
async setState(newState) {
|
|
276
|
+
async #setState(newState) {
|
|
275
277
|
if (newState === this.#current || this.#isTransitioning) {
|
|
276
278
|
return;
|
|
277
279
|
}
|
|
@@ -301,7 +303,7 @@ export default class PageMachine {
|
|
|
301
303
|
if (!doneCalled && nextState && nextState !== newState) {
|
|
302
304
|
doneCalled = true;
|
|
303
305
|
this.#isTransitioning = false;
|
|
304
|
-
this
|
|
306
|
+
this.#setState(nextState);
|
|
305
307
|
}
|
|
306
308
|
};
|
|
307
309
|
|