@doeixd/machine 1.2.0 → 1.3.0

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/README.md CHANGED
@@ -59,7 +59,9 @@ type Machine<C extends object> = {
59
59
  **Flexibility**: Unlike rigid FSM implementations, you can choose your level of immutability. Want to mutate? You can. Want pure functions? You can. Want compile-time state validation? Type-State Programming gives you that.
60
60
 
61
61
  **Read more about our core principles:** [ 📖 Core Principles Guide ](./docs/principles.md)
62
- **Explore our utility helpers:** [ 🏷️ Tagged Helpers & Utilities ](./docs/tagged-helpers.md)
62
+ **Learn about our recent refinements and workflows:** [ 🚀 Evolution & Workflows ](./docs/evolution.md)
63
+ **Prefer simplicity and little abstraction?** [ 🧘 The Minimalist's Manifesto (YAGNI) ](./docs/yagni.md)
64
+ **Explore our utility helpers (tag, isState, tag.factory, States):** [ 🏷️ Tagged Helpers & Utilities ](./docs/tagged-helpers.md)
63
65
 
64
66
  ## Choosing the Right Pattern
65
67
 
@@ -1715,12 +1715,14 @@ function state(context, transitions) {
1715
1715
  // src/index.ts
1716
1716
  function createMachine(context, fnsOrFactory) {
1717
1717
  if (typeof fnsOrFactory === "function") {
1718
+ let self;
1718
1719
  let transitions2;
1719
1720
  const transition = (newContext) => {
1720
- return createMachine(newContext, transitions2);
1721
+ return newContext === context ? self : createMachine(newContext, transitions2);
1721
1722
  };
1722
1723
  transitions2 = fnsOrFactory(transition);
1723
- return attachTransitions(Object.assign({ context }, transitions2), transitions2);
1724
+ self = attachTransitions(Object.assign({ context }, transitions2), transitions2);
1725
+ return self;
1724
1726
  }
1725
1727
  const stored = getStoredTransitions(fnsOrFactory);
1726
1728
  const transitions = stored != null ? stored : "context" in fnsOrFactory ? snapshotOwnTransitions(fnsOrFactory) : fnsOrFactory;