@hkdigital/lib-core 0.5.47 → 0.5.48

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,6 +69,10 @@ 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 {string} [config.name='PageMachine']
73
+ * Name for logger identification
74
+ * @param {import('../../../logging/typedef.js').LogLevel} [config.logLevel]
75
+ * Log level (defaults to INFO for state transitions)
72
76
  *
73
77
  * @example
74
78
  * ```javascript
@@ -93,12 +97,19 @@ export default class PageMachine {
93
97
  * });
94
98
  * ```
95
99
  */
96
- constructor({ startPath, routeMap, initialData, onEnterHooks }: {
100
+ constructor({ startPath, routeMap, initialData, onEnterHooks, name, logLevel }: {
97
101
  startPath: string;
98
102
  routeMap?: Record<string, string> | undefined;
99
103
  initialData?: Record<string, any> | undefined;
100
104
  onEnterHooks?: Record<string, Function> | undefined;
105
+ name?: string | undefined;
106
+ logLevel?: import("../../../logging/typedef.js").LogLevel | undefined;
101
107
  });
108
+ /**
109
+ * Logger instance for state machine
110
+ * @type {Logger}
111
+ */
112
+ logger: Logger;
102
113
  /**
103
114
  * Synchronize machine state with URL path
104
115
  *
@@ -323,3 +334,4 @@ export default class PageMachine {
323
334
  get canAbortTransitions(): boolean;
324
335
  #private;
325
336
  }
337
+ import { Logger } from '../../../logging/common.js';
@@ -1,3 +1,5 @@
1
+ import { Logger, INFO } from '../../../logging/common.js';
2
+
1
3
  /**
2
4
  * Base class for page state machines with URL route mapping
3
5
  *
@@ -57,6 +59,11 @@
57
59
  * ```
58
60
  */
59
61
  export default class PageMachine {
62
+ /**
63
+ * Logger instance for state machine
64
+ * @type {Logger}
65
+ */
66
+ logger;
60
67
  /**
61
68
  * Current state
62
69
  * @type {string}
@@ -145,6 +152,10 @@ export default class PageMachine {
145
152
  * Initial data properties (from server)
146
153
  * @param {Record<string, Function>} [config.onEnterHooks={}]
147
154
  * Map of states to onEnter hook functions
155
+ * @param {string} [config.name='PageMachine']
156
+ * Name for logger identification
157
+ * @param {import('../../../logging/typedef.js').LogLevel} [config.logLevel]
158
+ * Log level (defaults to INFO for state transitions)
148
159
  *
149
160
  * @example
150
161
  * ```javascript
@@ -169,11 +180,19 @@ export default class PageMachine {
169
180
  * });
170
181
  * ```
171
182
  */
172
- constructor({ startPath, routeMap = {}, initialData = {}, onEnterHooks = {} }) {
183
+ constructor({
184
+ startPath,
185
+ routeMap = {},
186
+ initialData = {},
187
+ onEnterHooks = {},
188
+ name = 'PageMachine',
189
+ logLevel = INFO
190
+ }) {
173
191
  if (!startPath) {
174
192
  throw new Error('PageMachine requires startPath parameter');
175
193
  }
176
194
 
195
+ this.logger = new Logger(name, logLevel);
177
196
  this.#startPath = startPath;
178
197
  this.#routeMap = routeMap;
179
198
  this.#data = initialData;
@@ -263,10 +282,14 @@ export default class PageMachine {
263
282
  this.#currentOnEnterHandler = null;
264
283
  this.#currentOnEnterDone = null;
265
284
 
285
+ const oldState = this.#current;
266
286
  this.#isTransitioning = true;
267
287
  this.#current = newState;
268
288
  this.#visitedStates.add(newState);
269
289
 
290
+ // Log state transition
291
+ this.logger.debug(`${oldState} → ${newState}`);
292
+
270
293
  // Check if this state has an onEnter hook
271
294
  const hookConfig = this.#onEnterHooks[newState];
272
295
  if (hookConfig?.onEnter) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-core",
3
- "version": "0.5.47",
3
+ "version": "0.5.48",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"