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