@doeixd/machine 0.0.11 → 0.0.12
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/index.js +55 -0
- package/dist/cjs/development/index.js.map +4 -4
- package/dist/cjs/production/index.js +4 -4
- package/dist/esm/development/index.js +55 -0
- package/dist/esm/development/index.js.map +4 -4
- package/dist/esm/production/index.js +3 -3
- package/dist/types/functional-combinators.d.ts +116 -0
- package/dist/types/functional-combinators.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/multi.d.ts +14 -0
- package/dist/types/multi.d.ts.map +1 -1
- package/dist/types/utils.d.ts +63 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/functional-combinators.ts +267 -0
- package/src/index.ts +12 -1
- package/src/multi.ts +36 -0
- package/src/utils.ts +74 -0
|
@@ -38,9 +38,11 @@ __export(src_exports, {
|
|
|
38
38
|
createAsyncMachine: () => createAsyncMachine,
|
|
39
39
|
createCustomMiddleware: () => createCustomMiddleware,
|
|
40
40
|
createEnsemble: () => createEnsemble,
|
|
41
|
+
createEnsembleFactory: () => createEnsembleFactory,
|
|
41
42
|
createEvent: () => createEvent,
|
|
42
43
|
createFetchMachine: () => createFetchMachine,
|
|
43
44
|
createFlow: () => createFlow,
|
|
45
|
+
createFunctionalMachine: () => createFunctionalMachine,
|
|
44
46
|
createMachine: () => createMachine,
|
|
45
47
|
createMachineBuilder: () => createMachineBuilder,
|
|
46
48
|
createMachineFactory: () => createMachineFactory,
|
|
@@ -51,6 +53,9 @@ __export(src_exports, {
|
|
|
51
53
|
createParallelMachine: () => createParallelMachine,
|
|
52
54
|
createPipeline: () => createPipeline,
|
|
53
55
|
createRunner: () => createRunner,
|
|
56
|
+
createTransition: () => createTransition,
|
|
57
|
+
createTransitionExtender: () => createTransitionExtender,
|
|
58
|
+
createTransitionFactory: () => createTransitionFactory,
|
|
54
59
|
delegateToChild: () => delegateToChild,
|
|
55
60
|
describe: () => describe,
|
|
56
61
|
extendTransitions: () => extendTransitions,
|
|
@@ -935,6 +940,11 @@ function createEnsemble(store, factories, getDiscriminant) {
|
|
|
935
940
|
actions
|
|
936
941
|
};
|
|
937
942
|
}
|
|
943
|
+
function createEnsembleFactory(store, getDiscriminant) {
|
|
944
|
+
return function withFactories(factories) {
|
|
945
|
+
return createEnsemble(store, factories, getDiscriminant);
|
|
946
|
+
};
|
|
947
|
+
}
|
|
938
948
|
function runWithRunner(flow, initialMachine) {
|
|
939
949
|
const runner = createRunner(initialMachine);
|
|
940
950
|
const generator = flow(runner);
|
|
@@ -2084,6 +2094,12 @@ function logState(machine, label) {
|
|
|
2084
2094
|
}
|
|
2085
2095
|
return machine;
|
|
2086
2096
|
}
|
|
2097
|
+
function createTransition(getTransitions, transformer) {
|
|
2098
|
+
return function(...args) {
|
|
2099
|
+
const nextContext = transformer(this.context, ...args);
|
|
2100
|
+
return createMachine(nextContext, getTransitions());
|
|
2101
|
+
};
|
|
2102
|
+
}
|
|
2087
2103
|
function call(fn, context, ...args) {
|
|
2088
2104
|
return fn.apply(context, args);
|
|
2089
2105
|
}
|
|
@@ -2131,6 +2147,45 @@ var BoundMachine = class _BoundMachine {
|
|
|
2131
2147
|
}
|
|
2132
2148
|
};
|
|
2133
2149
|
|
|
2150
|
+
// src/functional-combinators.ts
|
|
2151
|
+
function createTransitionFactory() {
|
|
2152
|
+
return function createTransition2(transformer) {
|
|
2153
|
+
return function(...args) {
|
|
2154
|
+
const nextContext = transformer(this.context, ...args);
|
|
2155
|
+
return createMachine(nextContext, this);
|
|
2156
|
+
};
|
|
2157
|
+
};
|
|
2158
|
+
}
|
|
2159
|
+
function createTransitionExtender(machine) {
|
|
2160
|
+
return {
|
|
2161
|
+
machine,
|
|
2162
|
+
addTransition: function(name, transformer) {
|
|
2163
|
+
const transitionFn = function(...args) {
|
|
2164
|
+
const nextContext = transformer(this.context, ...args);
|
|
2165
|
+
return createMachine(nextContext, this);
|
|
2166
|
+
};
|
|
2167
|
+
const newMachine = extendTransitions(machine, { [name]: transitionFn });
|
|
2168
|
+
return createTransitionExtender(newMachine);
|
|
2169
|
+
}
|
|
2170
|
+
};
|
|
2171
|
+
}
|
|
2172
|
+
function createFunctionalMachine(initialContext) {
|
|
2173
|
+
return function withTransitions(transformers) {
|
|
2174
|
+
const transitions = {};
|
|
2175
|
+
const machineTransitions = Object.fromEntries(
|
|
2176
|
+
Object.entries(transformers).map(([key, transformer]) => [
|
|
2177
|
+
key,
|
|
2178
|
+
function(...args) {
|
|
2179
|
+
const nextContext = transformer(this.context, ...args);
|
|
2180
|
+
return createMachine(nextContext, transitions);
|
|
2181
|
+
}
|
|
2182
|
+
])
|
|
2183
|
+
);
|
|
2184
|
+
Object.assign(transitions, machineTransitions);
|
|
2185
|
+
return createMachine(initialContext, transitions);
|
|
2186
|
+
};
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2134
2189
|
// src/index.ts
|
|
2135
2190
|
function createMachine(context, fns) {
|
|
2136
2191
|
const transitions = "context" in fns ? Object.fromEntries(
|