@doeixd/machine 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/cjs/development/core.js +39 -14
- package/dist/cjs/development/core.js.map +3 -3
- package/dist/cjs/development/index.js +51 -15
- package/dist/cjs/development/index.js.map +3 -3
- package/dist/cjs/development/react.js +39 -14
- package/dist/cjs/development/react.js.map +3 -3
- package/dist/cjs/production/core.js +1 -1
- package/dist/cjs/production/index.js +2 -2
- package/dist/cjs/production/react.js +1 -1
- package/dist/esm/development/core.js +39 -14
- package/dist/esm/development/core.js.map +3 -3
- package/dist/esm/development/index.js +51 -15
- package/dist/esm/development/index.js.map +3 -3
- package/dist/esm/development/react.js +39 -14
- package/dist/esm/development/react.js.map +3 -3
- package/dist/esm/production/core.js +1 -1
- package/dist/esm/production/index.js +2 -2
- package/dist/esm/production/react.js +1 -1
- package/dist/types/context-bound.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/internal-transitions.d.ts +5 -0
- package/dist/types/internal-transitions.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/context-bound.ts +14 -1
- package/src/index.ts +19 -15
- package/src/internal-transitions.ts +32 -0
|
@@ -122,6 +122,32 @@ __export(entry_react_exports, {
|
|
|
122
122
|
});
|
|
123
123
|
module.exports = __toCommonJS(entry_react_exports);
|
|
124
124
|
|
|
125
|
+
// src/internal-transitions.ts
|
|
126
|
+
var TRANSITIONS_SYMBOL = Symbol.for("__machine_transitions__");
|
|
127
|
+
function attachTransitions(machine, transitions) {
|
|
128
|
+
Object.defineProperty(machine, TRANSITIONS_SYMBOL, {
|
|
129
|
+
value: transitions,
|
|
130
|
+
enumerable: false,
|
|
131
|
+
configurable: false
|
|
132
|
+
});
|
|
133
|
+
return machine;
|
|
134
|
+
}
|
|
135
|
+
function getStoredTransitions(machine) {
|
|
136
|
+
if (!machine || typeof machine !== "object") {
|
|
137
|
+
return void 0;
|
|
138
|
+
}
|
|
139
|
+
return machine[TRANSITIONS_SYMBOL];
|
|
140
|
+
}
|
|
141
|
+
function snapshotOwnTransitions(source) {
|
|
142
|
+
if (!source || typeof source !== "object") {
|
|
143
|
+
return {};
|
|
144
|
+
}
|
|
145
|
+
const entries = Object.entries(source).filter(
|
|
146
|
+
([key, value]) => key !== "context" && typeof value === "function"
|
|
147
|
+
);
|
|
148
|
+
return Object.fromEntries(entries);
|
|
149
|
+
}
|
|
150
|
+
|
|
125
151
|
// src/generators.ts
|
|
126
152
|
function run(flow, initial) {
|
|
127
153
|
const generator = flow(initial);
|
|
@@ -1689,13 +1715,12 @@ function createMachine(context, fnsOrFactory) {
|
|
|
1689
1715
|
return createMachine(newContext, transitions2);
|
|
1690
1716
|
};
|
|
1691
1717
|
transitions2 = fnsOrFactory(transition);
|
|
1692
|
-
return Object.assign({ context }, transitions2);
|
|
1718
|
+
return attachTransitions(Object.assign({ context }, transitions2), transitions2);
|
|
1693
1719
|
}
|
|
1694
|
-
const
|
|
1695
|
-
|
|
1696
|
-
) : fnsOrFactory;
|
|
1720
|
+
const stored = getStoredTransitions(fnsOrFactory);
|
|
1721
|
+
const transitions = stored != null ? stored : "context" in fnsOrFactory ? snapshotOwnTransitions(fnsOrFactory) : fnsOrFactory;
|
|
1697
1722
|
const machine = Object.assign({ context }, transitions);
|
|
1698
|
-
return machine;
|
|
1723
|
+
return attachTransitions(machine, transitions);
|
|
1699
1724
|
}
|
|
1700
1725
|
function createAsyncMachine(context, fnsOrFactory) {
|
|
1701
1726
|
if (typeof fnsOrFactory === "function") {
|
|
@@ -1704,13 +1729,12 @@ function createAsyncMachine(context, fnsOrFactory) {
|
|
|
1704
1729
|
return createAsyncMachine(newContext, transitions2);
|
|
1705
1730
|
};
|
|
1706
1731
|
transitions2 = fnsOrFactory(transition);
|
|
1707
|
-
return Object.assign({ context }, transitions2);
|
|
1732
|
+
return attachTransitions(Object.assign({ context }, transitions2), transitions2);
|
|
1708
1733
|
}
|
|
1709
|
-
const
|
|
1710
|
-
|
|
1711
|
-
) : fnsOrFactory;
|
|
1734
|
+
const stored = getStoredTransitions(fnsOrFactory);
|
|
1735
|
+
const transitions = stored != null ? stored : "context" in fnsOrFactory ? snapshotOwnTransitions(fnsOrFactory) : fnsOrFactory;
|
|
1712
1736
|
const machine = Object.assign({ context }, transitions);
|
|
1713
|
-
return machine;
|
|
1737
|
+
return attachTransitions(machine, transitions);
|
|
1714
1738
|
}
|
|
1715
1739
|
function createMachineFactory() {
|
|
1716
1740
|
return (transformers) => {
|
|
@@ -1729,8 +1753,10 @@ function createMachineFactory() {
|
|
|
1729
1753
|
};
|
|
1730
1754
|
}
|
|
1731
1755
|
function setContext(machine, newContextOrFn) {
|
|
1732
|
-
|
|
1733
|
-
const
|
|
1756
|
+
var _a;
|
|
1757
|
+
const currentContext = machine.context;
|
|
1758
|
+
const transitions = (_a = getStoredTransitions(machine)) != null ? _a : snapshotOwnTransitions(machine);
|
|
1759
|
+
const newContext = typeof newContextOrFn === "function" ? newContextOrFn(currentContext) : newContextOrFn;
|
|
1734
1760
|
return createMachine(newContext, transitions);
|
|
1735
1761
|
}
|
|
1736
1762
|
function overrideTransitions(machine, overrides) {
|
|
@@ -1826,8 +1852,7 @@ var MachineBase = class {
|
|
|
1826
1852
|
}
|
|
1827
1853
|
};
|
|
1828
1854
|
function next(m, update) {
|
|
1829
|
-
|
|
1830
|
-
return createMachine(update(context), transitions);
|
|
1855
|
+
return setContext(m, (ctx) => update(ctx));
|
|
1831
1856
|
}
|
|
1832
1857
|
|
|
1833
1858
|
// src/react.ts
|