@statewalker/fsm 0.21.0 → 0.22.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.js +11 -22
- package/dist/{context → utils}/index.js +3 -3
- package/package.json +4 -4
- package/src/FsmBaseClass.ts +10 -6
- package/src/FsmProcess.ts +2 -4
- package/src/FsmState.ts +1 -2
- package/src/utils/bindMethods.ts +0 -7
- /package/dist/{context → utils}/index.d.ts +0 -0
- /package/src/{context → utils}/handlers.ts +0 -0
- /package/src/{context → utils}/index.ts +0 -0
- /package/src/{context → utils}/printer.ts +0 -0
- /package/src/{context → utils}/tracer.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
// src/utils/bindMethods.ts
|
|
2
|
-
function bindMethods(obj, ...methods) {
|
|
3
|
-
const o = obj;
|
|
4
|
-
methods.forEach((methodName) => {
|
|
5
|
-
o[methodName] = o[methodName].bind(o);
|
|
6
|
-
});
|
|
7
|
-
return obj;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
1
|
// src/FsmBaseClass.ts
|
|
11
2
|
var FsmBaseClass = class {
|
|
12
|
-
handlers;
|
|
13
|
-
data;
|
|
14
3
|
constructor() {
|
|
15
4
|
this.handlers = {};
|
|
16
5
|
this.data = {};
|
|
@@ -58,13 +47,16 @@ var FsmBaseClass = class {
|
|
|
58
47
|
console.error(error);
|
|
59
48
|
}
|
|
60
49
|
};
|
|
50
|
+
function bindMethods(obj, ...methods) {
|
|
51
|
+
const o = obj;
|
|
52
|
+
methods.forEach((methodName) => {
|
|
53
|
+
o[methodName] = o[methodName].bind(o);
|
|
54
|
+
});
|
|
55
|
+
return obj;
|
|
56
|
+
}
|
|
61
57
|
|
|
62
58
|
// src/FsmState.ts
|
|
63
59
|
var FsmState = class extends FsmBaseClass {
|
|
64
|
-
process;
|
|
65
|
-
key;
|
|
66
|
-
parent;
|
|
67
|
-
descriptor;
|
|
68
60
|
constructor(process, parent, key, descriptor) {
|
|
69
61
|
super();
|
|
70
62
|
this.process = process;
|
|
@@ -120,8 +112,10 @@ var EVENT_EMPTY = "";
|
|
|
120
112
|
|
|
121
113
|
// src/FsmStateDescriptor.ts
|
|
122
114
|
var FsmStateDescriptor = class _FsmStateDescriptor {
|
|
123
|
-
|
|
124
|
-
|
|
115
|
+
constructor() {
|
|
116
|
+
this.transitions = {};
|
|
117
|
+
this.states = {};
|
|
118
|
+
}
|
|
125
119
|
static build(config) {
|
|
126
120
|
const descriptor = new _FsmStateDescriptor();
|
|
127
121
|
for (const [from, event, to] of config.transitions || []) {
|
|
@@ -163,11 +157,6 @@ var STATUS_FINISHED = 16;
|
|
|
163
157
|
var STATUS_ENTER = STATUS_FIRST | STATUS_NEXT;
|
|
164
158
|
var STATUS_EXIT = STATUS_LEAF | STATUS_LAST;
|
|
165
159
|
var FsmProcess = class extends FsmBaseClass {
|
|
166
|
-
state;
|
|
167
|
-
event;
|
|
168
|
-
status;
|
|
169
|
-
config;
|
|
170
|
-
rootDescriptor;
|
|
171
160
|
constructor(config) {
|
|
172
161
|
super();
|
|
173
162
|
this.status = 0;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/utils/handlers.ts
|
|
2
2
|
var KEY_HANDLERS = "handlers";
|
|
3
3
|
function callStateHandlers(state) {
|
|
4
4
|
const key = state.key;
|
|
@@ -17,7 +17,7 @@ function addSubstateHandlers(state, handlers) {
|
|
|
17
17
|
state.setData(KEY_HANDLERS, index);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
// src/
|
|
20
|
+
// src/utils/printer.ts
|
|
21
21
|
var KEY_PRINTER = "printer";
|
|
22
22
|
function preparePrinter(process, { prefix = "", print = console.log, lineNumbers = false }) {
|
|
23
23
|
let lineCounter = 0;
|
|
@@ -47,7 +47,7 @@ function getPrinter(state) {
|
|
|
47
47
|
return state.getData(KEY_PRINTER, true) || getProcessPrinter(state.process);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
// src/
|
|
50
|
+
// src/utils/tracer.ts
|
|
51
51
|
function setProcessTracer(process, print) {
|
|
52
52
|
return process.onStateCreate((state) => {
|
|
53
53
|
setStateTracer(state, print);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statewalker/fsm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.1",
|
|
4
4
|
"description": "HFSM Implementation",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://github.com/statewalker/statewalker-fsm",
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
],
|
|
17
17
|
"module": "./dist/index.js",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
|
-
"jsdelivr": "./dist/index.js",
|
|
20
|
-
"unpkg": "./dist/index.js",
|
|
21
19
|
"types": "./dist/index.d.ts",
|
|
22
20
|
"exports": {
|
|
23
21
|
".": "./dist/index.js",
|
|
24
|
-
"./
|
|
22
|
+
"./utils": "./dist/utils/index.js",
|
|
23
|
+
"./*.ts": "./src/*.ts",
|
|
24
|
+
"./utils/*.ts": "./src/utils/*.ts"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@changesets/cli": "^2.27.7",
|
package/src/FsmBaseClass.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { bindMethods } from "./utils/bindMethods.ts";
|
|
2
|
-
|
|
3
1
|
export class FsmBaseClass {
|
|
4
|
-
handlers: Record<string, Function[]
|
|
5
|
-
data: Record<string, unknown
|
|
2
|
+
handlers: Record<string, Function[]> = {};
|
|
3
|
+
data: Record<string, unknown> = {};
|
|
6
4
|
constructor() {
|
|
7
|
-
this.handlers = {};
|
|
8
|
-
this.data = {};
|
|
9
5
|
bindMethods(this, "setData", "getData");
|
|
10
6
|
}
|
|
11
7
|
setData<T>(key: string, value: T) {
|
|
@@ -52,3 +48,11 @@ export class FsmBaseClass {
|
|
|
52
48
|
console.error(error);
|
|
53
49
|
}
|
|
54
50
|
}
|
|
51
|
+
|
|
52
|
+
export function bindMethods<T>(obj: T, ...methods: string[]) {
|
|
53
|
+
const o = obj as any;
|
|
54
|
+
methods.forEach((methodName) => {
|
|
55
|
+
o[methodName] = (o[methodName] as Function).bind(o);
|
|
56
|
+
});
|
|
57
|
+
return obj;
|
|
58
|
+
}
|
package/src/FsmProcess.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { bindMethods } from "./
|
|
2
|
-
import { FsmBaseClass } from "./FsmBaseClass.ts";
|
|
1
|
+
import { FsmBaseClass, bindMethods } from "./FsmBaseClass.ts";
|
|
3
2
|
import { FsmState, FsmStateDump, FsmStateSyncHandler } from "./FsmState.ts";
|
|
4
3
|
import {
|
|
5
4
|
EVENT_EMPTY,
|
|
@@ -39,13 +38,12 @@ export type FsmProcessDumpHandler = (
|
|
|
39
38
|
export class FsmProcess extends FsmBaseClass {
|
|
40
39
|
state?: FsmState;
|
|
41
40
|
event?: string;
|
|
42
|
-
status: number;
|
|
41
|
+
status: number = 0;
|
|
43
42
|
config: FsmStateConfig;
|
|
44
43
|
rootDescriptor: FsmStateDescriptor;
|
|
45
44
|
|
|
46
45
|
constructor(config: FsmStateConfig) {
|
|
47
46
|
super();
|
|
48
|
-
this.status = 0;
|
|
49
47
|
this.rootDescriptor = FsmStateDescriptor.build(config);
|
|
50
48
|
this.config = config;
|
|
51
49
|
bindMethods(this, "dispatch", "dump", "restore");
|
package/src/FsmState.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { bindMethods } from "./
|
|
2
|
-
import { FsmBaseClass } from "./FsmBaseClass.ts";
|
|
1
|
+
import { FsmBaseClass, bindMethods } from "./FsmBaseClass.ts";
|
|
3
2
|
import { FsmProcess } from "./FsmProcess.ts";
|
|
4
3
|
import { FsmStateDescriptor } from "./FsmStateDescriptor.ts";
|
|
5
4
|
|
package/src/utils/bindMethods.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|