diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c4d4ab --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +node_modules/ +babel/ +.babelrc +babel.config.json +package-lock.json +package.json +convert*.js \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3b66410 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "git.ignoreLimitWarning": true +} \ No newline at end of file diff --git a/src/xstate-fsm.js b/src/xstate-fsm.js index 927c25e..e4cbb6d 100644 --- a/src/xstate-fsm.js +++ b/src/xstate-fsm.js @@ -107,9 +107,12 @@ exports.createMachine = function createMachine(fsmConfig, options) { }, transition: (state, event) => { var _a, _b; - const { value, context } = typeof state === 'string' + // const { value, context } = typeof state === 'string' + var _obj = typeof state === 'string' ? { value: state, context: fsmConfig.context } : state; + value = _obj.value; + context = _obj.context; const eventObject = toEventObject(event); const stateConfig = fsmConfig.states[value]; if (!IS_PRODUCTION && !stateConfig) { @@ -121,12 +124,21 @@ exports.createMachine = function createMachine(fsmConfig, options) { if (transition === undefined) { return createUnchangedState(value, context); } - const { target, actions = [], cond = () => true } = typeof transition === 'string' - ? { target: transition } - : transition; + + // const { target, actions = [], cond = () => true } = typeof transition === 'string' + var _ref = typeof transition === 'string' ? { target: transition } : transition, + target = _ref.target, + _ref$actions = _ref.actions, + actions = _ref$actions === undefined ? [] : _ref$actions, + _ref$cond = _ref.cond, + cond = _ref$cond === undefined ? function () { + return true; + } : _ref$cond; + const isTargetless = target === undefined; const nextStateValue = target !== null && target !== void 0 ? target : value; const nextStateConfig = fsmConfig.states[nextStateValue]; + if (!IS_PRODUCTION && !nextStateConfig) { throw new Error(`State '${nextStateValue}' not found on machine ${(_b = fsmConfig.id) !== null && _b !== void 0 ? _b : ''}`); } @@ -136,7 +148,13 @@ exports.createMachine = function createMachine(fsmConfig, options) { : [] .concat(stateConfig.exit, actions, nextStateConfig.entry) .filter((a) => a)).map((action) => toActionObject(action, machine._options.actions)); - const [nonAssignActions, nextContext, assigned] = handleActions(allActions, context, eventObject); + + //const [nonAssignActions, nextContext, assigned] = handleActions(allActions, context, eventObject); + var _handleActions = handleActions(allActions, context, eventObject).slice(0,2); + nonAssignActions = _handleActions[0], + nextContext = _handleActions[1], + assigned = _handleActions[2]; + const resolvedTarget = target !== null && target !== void 0 ? target : value; return { value: resolvedTarget, diff --git a/test/Node/xstate-fsm/fsm.test.js b/test/Node/xstate-fsm/fsm.test.js index 04050d7..8b7e1bb 100644 --- a/test/Node/xstate-fsm/fsm.test.js +++ b/test/Node/xstate-fsm/fsm.test.js @@ -368,4 +368,4 @@ describe('interpreter', () => { const nextState = machine.transition(initialState, 'EVENT'); expect(nextState.actions.map((a) => a.type)).toEqual(['action']); }); -}); +}); \ No newline at end of file diff --git a/test/Node/xstate-fsm/fsm_test_baseline.PNG b/test/Node/xstate-fsm/fsm_test_baseline.PNG new file mode 100644 index 0000000..f5e6814 Binary files /dev/null and b/test/Node/xstate-fsm/fsm_test_baseline.PNG differ diff --git a/test/Node/xstate-fsm/jest.config.js b/test/Node/xstate-fsm/jest.config.js index 2959bc5..ce59073 100644 --- a/test/Node/xstate-fsm/jest.config.js +++ b/test/Node/xstate-fsm/jest.config.js @@ -14,7 +14,7 @@ module.exports = { // cacheDirectory: "C:\\Users\\simon_000\\AppData\\Local\\Temp\\jest", // Automatically clear mock calls and instances between every test - clearMocks: true, + // clearMocks: false, // Indicates whether the coverage information should be collected while executing the test // collectCoverage: false,