@axi-engine/states 0.2.1 → 0.3.1
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -6
- package/dist/index.mjs +3 -2
- package/package.json +4 -5
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -25,7 +25,8 @@ __export(index_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(index_exports);
|
|
26
26
|
|
|
27
27
|
// src/state-machine.ts
|
|
28
|
-
var
|
|
28
|
+
var import_ensure = require("@axijs/ensure");
|
|
29
|
+
var import_emitter = require("@axijs/emitter");
|
|
29
30
|
var StateMachine = class {
|
|
30
31
|
/**
|
|
31
32
|
* @protected
|
|
@@ -46,7 +47,7 @@ var StateMachine = class {
|
|
|
46
47
|
* console.log(`State transitioned from ${from} to ${to}`);
|
|
47
48
|
* });
|
|
48
49
|
*/
|
|
49
|
-
onChange = new
|
|
50
|
+
onChange = new import_emitter.Emitter();
|
|
50
51
|
/**
|
|
51
52
|
* Gets the current state of the machine.
|
|
52
53
|
* @returns The current state identifier, or `undefined` if the machine has not been started.
|
|
@@ -72,7 +73,7 @@ var StateMachine = class {
|
|
|
72
73
|
* });
|
|
73
74
|
*/
|
|
74
75
|
register(state, handler) {
|
|
75
|
-
if ((0,
|
|
76
|
+
if ((0, import_ensure.isUndefined)(handler) || (0, import_ensure.isFunction)(handler)) {
|
|
76
77
|
this.states.set(state, { onEnter: handler });
|
|
77
78
|
} else {
|
|
78
79
|
this.states.set(state, handler);
|
|
@@ -99,9 +100,9 @@ var StateMachine = class {
|
|
|
99
100
|
const oldState = this._state;
|
|
100
101
|
const oldStateConfig = this._state ? this.states.get(this._state) : void 0;
|
|
101
102
|
const newStateConfig = this.states.get(newState);
|
|
102
|
-
(0,
|
|
103
|
-
(0,
|
|
104
|
-
!(0,
|
|
103
|
+
(0, import_ensure.throwIfEmpty)(newStateConfig, `State ${String(newState)} is not registered.`);
|
|
104
|
+
(0, import_ensure.throwIf)(
|
|
105
|
+
!(0, import_ensure.isNullOrUndefined)(newStateConfig.allowedFrom) && !(0, import_ensure.isNullOrUndefined)(oldState) && !newStateConfig.allowedFrom.includes(oldState),
|
|
105
106
|
`Transition from ${String(oldState)} to ${String(newState)} is not allowed.`
|
|
106
107
|
);
|
|
107
108
|
await oldStateConfig?.onExit?.();
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/state-machine.ts
|
|
2
|
-
import {
|
|
2
|
+
import { isFunction, isNullOrUndefined, isUndefined, throwIf, throwIfEmpty } from "@axijs/ensure";
|
|
3
|
+
import { Emitter } from "@axijs/emitter";
|
|
3
4
|
var StateMachine = class {
|
|
4
5
|
/**
|
|
5
6
|
* @protected
|
|
@@ -46,7 +47,7 @@ var StateMachine = class {
|
|
|
46
47
|
* });
|
|
47
48
|
*/
|
|
48
49
|
register(state, handler) {
|
|
49
|
-
if (isUndefined(handler) ||
|
|
50
|
+
if (isUndefined(handler) || isFunction(handler)) {
|
|
50
51
|
this.states.set(state, { onEnter: handler });
|
|
51
52
|
} else {
|
|
52
53
|
this.states.set(state, handler);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axi-engine/states",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
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": {
|
|
@@ -38,10 +38,9 @@
|
|
|
38
38
|
"files": [
|
|
39
39
|
"dist"
|
|
40
40
|
],
|
|
41
|
-
"devDependencies": {
|
|
42
|
-
"@axi-engine/utils": "^0.2.1"
|
|
43
|
-
},
|
|
44
41
|
"peerDependencies": {
|
|
45
|
-
"@
|
|
42
|
+
"@axijs/emitter": "^1.0.0",
|
|
43
|
+
"@axijs/ensure": "^1.0.0",
|
|
44
|
+
"@axi-engine/utils": "^0.3.0"
|
|
46
45
|
}
|
|
47
46
|
}
|