@axi-engine/states 0.3.1 → 0.3.2

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.
package/dist/index.d.mts CHANGED
@@ -1,9 +1,32 @@
1
1
  import { Emitter } from '@axijs/emitter';
2
2
 
3
+ /**
4
+ * Represents a lifecycle handler function for a state.
5
+ * If a payload type `P` is provided and is not `void`, the handler receives the payload.
6
+ * Supports both synchronous and asynchronous execution.
7
+ *
8
+ * @template P The type of the payload passed to the handler.
9
+ */
3
10
  type StateHandler<P = void> = P extends void ? () => void | Promise<void> : (payload: P) => void | Promise<void>;
11
+ /**
12
+ * Configuration object for defining a state's behavior and transition rules.
13
+ *
14
+ * @template T The type used for state identifiers.
15
+ * @template P The type of the payload passed to the `onEnter` handler.
16
+ */
4
17
  interface StateHandlerConfig<T, P = void> {
18
+ /**
19
+ * Hook executed when transitioning into this state.
20
+ */
5
21
  onEnter?: StateHandler<P>;
22
+ /**
23
+ * Hook executed when transitioning out of this state.
24
+ */
6
25
  onExit?: () => void | Promise<void>;
26
+ /**
27
+ * Optional list of states from which a transition to this state is permitted.
28
+ * If undefined, the state can be entered from any state.
29
+ */
7
30
  allowedFrom?: T[];
8
31
  }
9
32
  type StateHandlerRegistration<T, P = void> = StateHandler<P> | StateHandlerConfig<T, P>;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,32 @@
1
1
  import { Emitter } from '@axijs/emitter';
2
2
 
3
+ /**
4
+ * Represents a lifecycle handler function for a state.
5
+ * If a payload type `P` is provided and is not `void`, the handler receives the payload.
6
+ * Supports both synchronous and asynchronous execution.
7
+ *
8
+ * @template P The type of the payload passed to the handler.
9
+ */
3
10
  type StateHandler<P = void> = P extends void ? () => void | Promise<void> : (payload: P) => void | Promise<void>;
11
+ /**
12
+ * Configuration object for defining a state's behavior and transition rules.
13
+ *
14
+ * @template T The type used for state identifiers.
15
+ * @template P The type of the payload passed to the `onEnter` handler.
16
+ */
4
17
  interface StateHandlerConfig<T, P = void> {
18
+ /**
19
+ * Hook executed when transitioning into this state.
20
+ */
5
21
  onEnter?: StateHandler<P>;
22
+ /**
23
+ * Hook executed when transitioning out of this state.
24
+ */
6
25
  onExit?: () => void | Promise<void>;
26
+ /**
27
+ * Optional list of states from which a transition to this state is permitted.
28
+ * If undefined, the state can be entered from any state.
29
+ */
7
30
  allowedFrom?: T[];
8
31
  }
9
32
  type StateHandlerRegistration<T, P = void> = StateHandler<P> | StateHandlerConfig<T, P>;
package/dist/index.js CHANGED
@@ -98,7 +98,7 @@ var StateMachine = class {
98
98
  */
99
99
  async call(newState, payload) {
100
100
  const oldState = this._state;
101
- const oldStateConfig = this._state ? this.states.get(this._state) : void 0;
101
+ const oldStateConfig = (0, import_ensure.isUndefined)(this._state) ? void 0 : this.states.get(this._state);
102
102
  const newStateConfig = this.states.get(newState);
103
103
  (0, import_ensure.throwIfEmpty)(newStateConfig, `State ${String(newState)} is not registered.`);
104
104
  (0, import_ensure.throwIf)(
package/dist/index.mjs CHANGED
@@ -72,7 +72,7 @@ var StateMachine = class {
72
72
  */
73
73
  async call(newState, payload) {
74
74
  const oldState = this._state;
75
- const oldStateConfig = this._state ? this.states.get(this._state) : void 0;
75
+ const oldStateConfig = isUndefined(this._state) ? void 0 : this.states.get(this._state);
76
76
  const newStateConfig = this.states.get(newState);
77
77
  throwIfEmpty(newStateConfig, `State ${String(newState)} is not registered.`);
78
78
  throwIf(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axi-engine/states",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "A minimal, type-safe state machine for the Axi Engine, designed for managing game logic and component states with a simple API.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -32,8 +32,9 @@
32
32
  },
33
33
  "scripts": {
34
34
  "build": "tsup",
35
- "docs": "typedoc src/index.ts --out docs/api --options ../../typedoc.json",
36
- "test": "echo 'No tests yet for @axi-engine/states'"
35
+ "prebuild": "npm test",
36
+ "test": "vitest run",
37
+ "docs": "typedoc src/index.ts --out docs/api --options ../../typedoc.json"
37
38
  },
38
39
  "files": [
39
40
  "dist"