b02b2f708c
## Changes - Update packages - Migrate to Typescript - Refactor Component structure - Normalize Code style ## Documentation / Examples - [x] Make sure the linting passes by running `pnpm lint` - [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
26 lines
581 B
TypeScript
26 lines
581 B
TypeScript
import { createMachine, assign } from 'xstate'
|
|
|
|
type CounterContext = {
|
|
count: number
|
|
}
|
|
|
|
type CounterEvents = {
|
|
type: 'INC' | 'DEC' | 'RESET'
|
|
}
|
|
|
|
export const counterMachine = createMachine<CounterContext, CounterEvents>({
|
|
predictableActionArguments: true,
|
|
initial: 'active',
|
|
context: {
|
|
count: 0,
|
|
},
|
|
states: {
|
|
active: {
|
|
on: {
|
|
INC: { actions: assign({ count: (context) => context.count + 1 }) },
|
|
DEC: { actions: assign({ count: (context) => context.count - 1 }) },
|
|
RESET: { actions: assign({ count: 0 }) },
|
|
},
|
|
},
|
|
},
|
|
})
|