Skip to content

Commit

Permalink
Merge branch 'main' into next
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/core/package.json
#	packages/core/src/interpreter.ts
#	packages/xstate-analytics/package.json
#	packages/xstate-graph/package.json
#	packages/xstate-immer/package.json
#	packages/xstate-inspect/package.json
#	packages/xstate-react/package.json
#	packages/xstate-scxml/package.json
#	packages/xstate-svelte/package.json
#	packages/xstate-test/package.json
#	packages/xstate-vue/package.json
  • Loading branch information
Andarist committed Aug 11, 2022
2 parents 3fd44ff + f2bf492 commit 74fbf64
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
5 changes: 3 additions & 2 deletions docs/guides/delays.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,16 @@ import { interpret } from 'xstate';
// import { SimulatedClock } from 'xstate/lib/interpreter'; // < 4.6.0
import { SimulatedClock } from 'xstate/lib/SimulatedClock'; // >= 4.6.0

const simulatedClock = new SimulatedClock();
const service = interpret(lightDelayMachine, {
clock: new SimulatedClock()
clock: simulatedClock
}).onTransition((state) => console.log(state.value));

service.start();
// => 'green'

// move the SimulatedClock forward by 1 second
service.clock.increment(1000);
simulatedClock.increment(1000);
// => 'yellow'
```

Expand Down
6 changes: 6 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# xstate

## 4.33.1

### Patch Changes

- [#3514](https://github.com/statelyai/xstate/pull/3514) [`b451f5789`](https://github.com/statelyai/xstate/commit/b451f5789fdfcfe05b9212e6754ae07ed0ee7cf3) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with `.nextState(event)` calls accidentally executing actions in machines with `predictableActionArguments`.

## 4.33.0

### Minor Changes
Expand Down
11 changes: 4 additions & 7 deletions packages/core/src/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,10 @@ export class Interpreter<
}
}
public _nextState(
event: Event<TEvent> | SCXML.Event<TEvent>
event: Event<TEvent> | SCXML.Event<TEvent>,
exec = !!this.machine.config.predictableActionArguments && this._exec
): State<TContext, TEvent, TResolvedTypesMeta> {
return this.machine._transition(
this.state,
event,
this.machine.config.predictableActionArguments ? this._exec : undefined
);
return this.machine._transition(this.state, event, exec || undefined);
}
/**
* Returns the next state given the interpreter's current state and the event.
Expand All @@ -655,7 +652,7 @@ export class Interpreter<
public nextState(
event: Event<TEvent> | SCXML.Event<TEvent>
): State<TContext, TEvent, TResolvedTypesMeta> {
return this._nextState(event);
return this._nextState(event, false);
}

private forward(event: SCXML.Event<TEvent>): void {
Expand Down
18 changes: 18 additions & 0 deletions packages/core/test/predictableExec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,22 @@ describe('predictableExec', () => {

expect(actual).toEqual([0, 1, 2]);
});

it('`.nextState()` should not execute actions `predictableActionArguments`', () => {
let spy = jest.fn();

const machine = createMachine({
predictableActionArguments: true,
on: {
TICK: {
actions: spy
}
}
});

const service = interpret(machine).start();
service.nextState({ type: 'TICK' });

expect(spy).not.toBeCalled();
});
});

0 comments on commit 74fbf64

Please sign in to comment.