@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.
@@ -2084,9 +2084,10 @@ function freeze(obj) {
2084
2084
 
2085
2085
  // src/minimal.ts
2086
2086
  function machine(context, factory2) {
2087
- const next2 = (newContext) => machine(newContext, factory2);
2088
- const transitions = factory2(context, next2);
2089
- return Object.assign({}, context, transitions);
2087
+ let self;
2088
+ const next2 = (newContext) => newContext === context ? self : machine(newContext, factory2);
2089
+ self = Object.assign({}, context, factory2(context, next2));
2090
+ return self;
2090
2091
  }
2091
2092
  function match(state2, cases) {
2092
2093
  const handler = cases[state2.tag];
@@ -2173,13 +2174,20 @@ function withChildren(parent, children) {
2173
2174
  return result;
2174
2175
  }
2175
2176
  function factory() {
2176
- return (transitionFactory) => (context) => machine(context, transitionFactory);
2177
+ return (transitionFactory) => {
2178
+ const resultFactory = (context) => {
2179
+ const next2 = (c) => resultFactory(c);
2180
+ return machine(context, (ctx) => transitionFactory(ctx, next2));
2181
+ };
2182
+ return resultFactory;
2183
+ };
2177
2184
  }
2178
2185
  function union() {
2179
2186
  return (factories) => {
2180
2187
  const resultFactory = (context) => {
2181
2188
  const factoryFn = factories[context.tag];
2182
- return machine(context, (ctx, _next) => factoryFn(ctx, resultFactory));
2189
+ const next2 = (c) => resultFactory(c);
2190
+ return machine(context, (ctx) => factoryFn(ctx, next2));
2183
2191
  };
2184
2192
  return resultFactory;
2185
2193
  };
@@ -2257,12 +2265,14 @@ function renameMap() {
2257
2265
  // src/index.ts
2258
2266
  function createMachine(context, fnsOrFactory) {
2259
2267
  if (typeof fnsOrFactory === "function") {
2268
+ let self;
2260
2269
  let transitions2;
2261
2270
  const transition = (newContext) => {
2262
- return createMachine(newContext, transitions2);
2271
+ return newContext === context ? self : createMachine(newContext, transitions2);
2263
2272
  };
2264
2273
  transitions2 = fnsOrFactory(transition);
2265
- return attachTransitions(Object.assign({ context }, transitions2), transitions2);
2274
+ self = attachTransitions(Object.assign({ context }, transitions2), transitions2);
2275
+ return self;
2266
2276
  }
2267
2277
  const stored = getStoredTransitions(fnsOrFactory);
2268
2278
  const transitions = stored != null ? stored : "context" in fnsOrFactory ? snapshotOwnTransitions(fnsOrFactory) : fnsOrFactory;