MCPcopy
hub / github.com/statelyai/xstate / createCounterMachine

Function createCounterMachine

packages/core/test/assign.test.ts:9–91  ·  view source on GitHub ↗
(context: Partial<CounterContext> = {})

Source from the content-addressed store, hash-verified

7}
8
9const 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 }

Callers 1

assign.test.tsFile · 0.85

Calls 2

createMachineFunction · 0.90
assignFunction · 0.90

Tested by

no test coverage detected