@praxisjs/fsm 1.0.1 → 1.0.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @praxisjs/fsm
2
2
 
3
+ ## 1.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 9117b52:
8
+ - Updated dependencies [2b8c768]
9
+ - @praxisjs/decorators@0.7.0
10
+
11
+ ## 1.0.2
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [72cd9a8]
16
+ - @praxisjs/decorators@0.6.1
17
+
3
18
  ## 1.0.1
4
19
 
5
20
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAQA,OAAO,EAA+B,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEhF,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAe5B,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,OAAO,EAAE,2BAA2B,CAAC,GAAG,CAAC,KAAK,IAAI,CAC3H;AA6BD,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAC7D,UAAU,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,EACnC,WAAW,SAAY,GAKQ,CAAC,KAAK,EAAE,QAAQ,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,OAAO,EAAE,qBAAqB,KAAK,QAAQ,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CACrK"}
1
+ {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAQA,OAAO,EAA+B,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEhF,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAiB5B,CAC7B,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EAEtC,OAAO,EAAE,2BAA2B,CAAC,GAAG,CAAC,KACtC,IAAI,CACV;AAqCD,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAC7D,UAAU,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,EACnC,WAAW,SAAY,GAOQ,CAC7B,KAAK,EAAE,QAAQ,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EACnD,OAAO,EAAE,qBAAqB,KAC3B,QAAQ,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAClD"}
@@ -15,7 +15,6 @@ export function Transition(machineProp, event) {
15
15
  },
16
16
  });
17
17
  // FSM decorators work on any class, not just StatefulComponent
18
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
18
  return decorator;
20
19
  }
21
20
  class StateMachineBehavior extends ClassBehavior {
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,GAEd,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,aAAa,EAAwC,MAAM,WAAW,CAAC;AAEhF,MAAM,UAAU,UAAU,CAAC,WAAmB,EAAE,KAAa;IAC3D,MAAM,SAAS,GAAG,qBAAqB,CAAC;QACtC,IAAI,CAAC,QAAQ,EAAE,QAAQ;YACrB,OAAO,CAAC,GAAG,IAAe,EAAE,EAAE;gBAC5B,MAAM,OAAO,GAAI,QAAoC,CAAC,WAAW,CAAwC,CAAC;gBAC1G,IAAI,CAAC,OAAO,EAAE,CAAC;oBACb,OAAO,CAAC,IAAI,CAAC,iBAAiB,WAAW,2BAA2B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I,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;oBACrB,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;gBAChD,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAkB,CAAC;YAC7C,CAAC;YACD,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,IAAI;SACnB,CACF,CAAC;IACJ,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAC1B,UAAmC,EACnC,WAAW,GAAG,SAAS;IAEvB,MAAM,SAAS,GAAG,oBAAoB,CACpC,IAAI,oBAAoB,CAAC,UAAU,EAAE,WAAW,CAAC,CAClD,CAAC;IACF,2DAA2D;IAE3D,OAAO,SAG0C,CAAC;AACpD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@praxisjs/fsm",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@praxisjs/core": "1.1.0",
18
- "@praxisjs/decorators": "0.6.0",
18
+ "@praxisjs/decorators": "0.7.0",
19
19
  "@praxisjs/shared": "0.2.0"
20
20
  },
21
21
  "scripts": {
package/src/decorators.ts CHANGED
@@ -12,21 +12,30 @@ export function Transition(machineProp: string, event: string) {
12
12
  const decorator = createMethodDecorator({
13
13
  wrap(original, instance) {
14
14
  return (...args: unknown[]) => {
15
- const machine = (instance as Record<string, unknown>)[machineProp] as Machine<string, string> | undefined;
15
+ const machine = (instance as Record<string, unknown>)[machineProp] as
16
+ | Machine<string, string>
17
+ | undefined;
16
18
  if (!machine) {
17
19
  console.warn(`[Transition] "${machineProp}" is not a state machine.`);
18
20
  return;
19
21
  }
20
- if (machine.send(event)) return original.apply(instance, args);
22
+ if (machine.send(event))
23
+ return original.apply(instance, args) as unknown;
21
24
  };
22
25
  },
23
26
  });
24
27
  // FSM decorators work on any class, not just StatefulComponent
25
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
- return decorator as unknown as (value: (...args: unknown[]) => unknown, context: ClassMethodDecoratorContext<any>) => void;
28
+ return decorator as unknown as (
29
+ value: (...args: unknown[]) => unknown,
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ context: ClassMethodDecoratorContext<any>,
32
+ ) => void;
27
33
  }
28
34
 
29
- class StateMachineBehavior<S extends string, E extends string> extends ClassBehavior {
35
+ class StateMachineBehavior<
36
+ S extends string,
37
+ E extends string,
38
+ > extends ClassBehavior {
30
39
  constructor(
31
40
  private readonly definition: MachineDefinition<S, E>,
32
41
  private readonly propertyKey: string,
@@ -42,14 +51,19 @@ class StateMachineBehavior<S extends string, E extends string> extends ClassBeha
42
51
  initialize(Enhanced: new (...args: any[]) => unknown): void {
43
52
  const machines = new WeakMap<object, Machine<S, E>>();
44
53
  const { definition, propertyKey } = this;
45
- Object.defineProperty((Enhanced as { prototype: object }).prototype, propertyKey, {
46
- get(this: object): Machine<S, E> {
47
- if (!machines.has(this)) machines.set(this, createMachine(definition));
48
- return machines.get(this) as Machine<S, E>;
54
+ Object.defineProperty(
55
+ (Enhanced as { prototype: object }).prototype,
56
+ propertyKey,
57
+ {
58
+ get(this: object): Machine<S, E> {
59
+ if (!machines.has(this))
60
+ machines.set(this, createMachine(definition));
61
+ return machines.get(this) as Machine<S, E>;
62
+ },
63
+ enumerable: true,
64
+ configurable: true,
49
65
  },
50
- enumerable: true,
51
- configurable: true,
52
- });
66
+ );
53
67
  }
54
68
  }
55
69
 
@@ -57,8 +71,13 @@ export function StateMachine<S extends string, E extends string>(
57
71
  definition: MachineDefinition<S, E>,
58
72
  propertyKey = "machine",
59
73
  ) {
60
- const decorator = createClassDecorator(new StateMachineBehavior(definition, propertyKey));
74
+ const decorator = createClassDecorator(
75
+ new StateMachineBehavior(definition, propertyKey),
76
+ );
61
77
  // FSM decorators work on any class, not just RootComponent
62
-
63
- return decorator as unknown as (value: abstract new (...args: unknown[]) => unknown, context: ClassDecoratorContext) => abstract new (...args: unknown[]) => unknown;
78
+
79
+ return decorator as unknown as (
80
+ value: abstract new (...args: unknown[]) => unknown,
81
+ context: ClassDecoratorContext,
82
+ ) => abstract new (...args: unknown[]) => unknown;
64
83
  }