coremachine 1.0.1 → 1.0.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.ts CHANGED
@@ -47,6 +47,7 @@ export type ActionMessage<T extends MachineConfig<any, any>> = {
47
47
  };
48
48
  }[ExtractActions<T> & string];
49
49
  export type StateMessage<T extends MachineConfig<any, any>> = {
50
+ previousState?: ExtractStates<T>;
50
51
  state: ExtractStates<T>;
51
52
  context: ExtractContext<T>;
52
53
  };
package/dist/index.js CHANGED
@@ -43,7 +43,11 @@ export class Coremachine extends Duplex {
43
43
  }
44
44
  if (this._eager) {
45
45
  // @ts-ignore
46
- this.push({ state: this._state, context: this._context });
46
+ this.push({
47
+ previousState: lastState.state,
48
+ state: this._state,
49
+ context: this._context,
50
+ });
47
51
  }
48
52
  }
49
53
  cb();
@@ -51,7 +55,9 @@ export class Coremachine extends Duplex {
51
55
  .catch(cb);
52
56
  }
53
57
  _write(chunk, cb) {
54
- this.action(chunk.action, chunk.value).then(() => cb(), cb);
58
+ this.action(chunk.action, chunk.value)
59
+ .then(() => cb())
60
+ .catch((e) => cb(e));
55
61
  }
56
62
  _read(cb) {
57
63
  cb();
@@ -66,7 +72,6 @@ export class Coremachine extends Duplex {
66
72
  if (!transition) {
67
73
  throw new Error(`Invalid action: ${String(action)} for state ${this._state}`);
68
74
  }
69
- const oldState = structuredClone(this._context);
70
75
  await transition.action(this._context, value);
71
76
  await this._core.append({
72
77
  state: transition.target || this._state,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "coremachine",
3
3
  "type": "module",
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "author": {
6
6
  "name": "Dominic Cassidy",
7
7
  "email": "dominic@cassidy.casa",