Skip to content

Commit

Permalink
fix destructuring issues #6 #7 #8 #9
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonGAndrews committed Aug 31, 2021
1 parent 2f6b206 commit 49ae4f2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules/
babel/
.babelrc
babel.config.json
package-lock.json
package.json
convert*.js
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"git.ignoreLimitWarning": true
}
28 changes: 23 additions & 5 deletions src/xstate-fsm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 : ''}`);
}
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/Node/xstate-fsm/fsm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,4 @@ describe('interpreter', () => {
const nextState = machine.transition(initialState, 'EVENT');
expect(nextState.actions.map((a) => a.type)).toEqual(['action']);
});
});
});
Binary file added test/Node/xstate-fsm/fsm_test_baseline.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/Node/xstate-fsm/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 49ae4f2

Please sign in to comment.