(context: Partial<CounterContext> = {})
| 7 | } |
| 8 | |
| 9 | const createCounterMachine = (context: Partial<CounterContext> = {}) => |
| 10 | createMachine({ |
| 11 | types: {} as { context: CounterContext }, |
| 12 | initial: 'counting', |
| 13 | context: { count: 0, foo: 'bar', ...context }, |
| 14 | states: { |
| 15 | counting: { |
| 16 | on: { |
| 17 | INC: [ |
| 18 | { |
| 19 | target: 'counting', |
| 20 | actions: assign(({ context }) => ({ |
| 21 | count: context.count + 1 |
| 22 | })) |
| 23 | } |
| 24 | ], |
| 25 | DEC: [ |
| 26 | { |
| 27 | target: 'counting', |
| 28 | actions: [ |
| 29 | assign({ |
| 30 | count: ({ context }) => context.count - 1 |
| 31 | }) |
| 32 | ] |
| 33 | } |
| 34 | ], |
| 35 | WIN_PROP: [ |
| 36 | { |
| 37 | target: 'counting', |
| 38 | actions: [ |
| 39 | assign({ |
| 40 | count: () => 100, |
| 41 | foo: () => 'win' |
| 42 | }) |
| 43 | ] |
| 44 | } |
| 45 | ], |
| 46 | WIN_STATIC: [ |
| 47 | { |
| 48 | target: 'counting', |
| 49 | actions: [ |
| 50 | assign({ |
| 51 | count: 100, |
| 52 | foo: 'win' |
| 53 | }) |
| 54 | ] |
| 55 | } |
| 56 | ], |
| 57 | WIN_MIX: [ |
| 58 | { |
| 59 | target: 'counting', |
| 60 | actions: [ |
| 61 | assign({ |
| 62 | count: () => 100, |
| 63 | foo: 'win' |
| 64 | }) |
| 65 | ] |
| 66 | } |
no test coverage detected