@hkdigital/lib-core 0.5.48 → 0.5.49
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.
|
@@ -69,10 +69,8 @@ export default class PageMachine {
|
|
|
69
69
|
* Initial data properties (from server)
|
|
70
70
|
* @param {Record<string, Function>} [config.onEnterHooks={}]
|
|
71
71
|
* Map of states to onEnter hook functions
|
|
72
|
-
* @param {
|
|
73
|
-
*
|
|
74
|
-
* @param {import('../../../logging/typedef.js').LogLevel} [config.logLevel]
|
|
75
|
-
* Log level (defaults to INFO for state transitions)
|
|
72
|
+
* @param {import('../../../logging/client.js').Logger} [config.logger]
|
|
73
|
+
* Logger instance (optional, if not provided no logging occurs)
|
|
76
74
|
*
|
|
77
75
|
* @example
|
|
78
76
|
* ```javascript
|
|
@@ -97,19 +95,18 @@ export default class PageMachine {
|
|
|
97
95
|
* });
|
|
98
96
|
* ```
|
|
99
97
|
*/
|
|
100
|
-
constructor({ startPath, routeMap, initialData, onEnterHooks,
|
|
98
|
+
constructor({ startPath, routeMap, initialData, onEnterHooks, logger }: {
|
|
101
99
|
startPath: string;
|
|
102
100
|
routeMap?: Record<string, string> | undefined;
|
|
103
101
|
initialData?: Record<string, any> | undefined;
|
|
104
102
|
onEnterHooks?: Record<string, Function> | undefined;
|
|
105
|
-
|
|
106
|
-
logLevel?: import("../../../logging/typedef.js").LogLevel | undefined;
|
|
103
|
+
logger?: import("../../../logging/client.js").Logger | undefined;
|
|
107
104
|
});
|
|
108
105
|
/**
|
|
109
106
|
* Logger instance for state machine
|
|
110
|
-
* @type {Logger}
|
|
107
|
+
* @type {import('../../../logging/client.js').Logger}
|
|
111
108
|
*/
|
|
112
|
-
logger: Logger;
|
|
109
|
+
logger: import("../../../logging/client.js").Logger;
|
|
113
110
|
/**
|
|
114
111
|
* Synchronize machine state with URL path
|
|
115
112
|
*
|
|
@@ -334,4 +331,3 @@ export default class PageMachine {
|
|
|
334
331
|
get canAbortTransitions(): boolean;
|
|
335
332
|
#private;
|
|
336
333
|
}
|
|
337
|
-
import { Logger } from '../../../logging/common.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { INFO } from '../../../logging/common.js';
|
|
2
|
+
import { createClientLogger } from '../../../logging/client.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Base class for page state machines with URL route mapping
|
|
@@ -61,7 +62,7 @@ import { Logger, INFO } from '../../../logging/common.js';
|
|
|
61
62
|
export default class PageMachine {
|
|
62
63
|
/**
|
|
63
64
|
* Logger instance for state machine
|
|
64
|
-
* @type {Logger}
|
|
65
|
+
* @type {import('../../../logging/client.js').Logger}
|
|
65
66
|
*/
|
|
66
67
|
logger;
|
|
67
68
|
/**
|
|
@@ -152,10 +153,8 @@ export default class PageMachine {
|
|
|
152
153
|
* Initial data properties (from server)
|
|
153
154
|
* @param {Record<string, Function>} [config.onEnterHooks={}]
|
|
154
155
|
* Map of states to onEnter hook functions
|
|
155
|
-
* @param {
|
|
156
|
-
*
|
|
157
|
-
* @param {import('../../../logging/typedef.js').LogLevel} [config.logLevel]
|
|
158
|
-
* Log level (defaults to INFO for state transitions)
|
|
156
|
+
* @param {import('../../../logging/client.js').Logger} [config.logger]
|
|
157
|
+
* Logger instance (optional, if not provided no logging occurs)
|
|
159
158
|
*
|
|
160
159
|
* @example
|
|
161
160
|
* ```javascript
|
|
@@ -185,14 +184,13 @@ export default class PageMachine {
|
|
|
185
184
|
routeMap = {},
|
|
186
185
|
initialData = {},
|
|
187
186
|
onEnterHooks = {},
|
|
188
|
-
|
|
189
|
-
logLevel = INFO
|
|
187
|
+
logger = null
|
|
190
188
|
}) {
|
|
191
189
|
if (!startPath) {
|
|
192
190
|
throw new Error('PageMachine requires startPath parameter');
|
|
193
191
|
}
|
|
194
192
|
|
|
195
|
-
this.logger =
|
|
193
|
+
this.logger = logger;
|
|
196
194
|
this.#startPath = startPath;
|
|
197
195
|
this.#routeMap = routeMap;
|
|
198
196
|
this.#data = initialData;
|
|
@@ -288,7 +286,7 @@ export default class PageMachine {
|
|
|
288
286
|
this.#visitedStates.add(newState);
|
|
289
287
|
|
|
290
288
|
// Log state transition
|
|
291
|
-
this.logger
|
|
289
|
+
this.logger?.debug(`${oldState} → ${newState}`);
|
|
292
290
|
|
|
293
291
|
// Check if this state has an onEnter hook
|
|
294
292
|
const hookConfig = this.#onEnterHooks[newState];
|