Skip to content
Source
Sign inSign up
TanStack/devtools
Open History to see the last commit

counter.ts

29 lines599 Bytes

1import { DevtoolsEventClient } from './eventClient.ts'
2​
3export function createCounter() {
4 let count = 0
5 const history: Array<number> = []
6​
7 return {
8 getCount: () => count,
9 increment: () => {
10 count++
11 history.push(count)
12​
13 // The emit eventSuffix must match that of the EventMap defined in eventClient.ts
14 DevtoolsEventClient.emit('counter-state', {
15 count,
16 history,
17 })
18 },
19 decrement: () => {
20 count--
21 history.push(count)
22​
23 DevtoolsEventClient.emit('counter-state', {
24 count,
25 history,
26 })
27 },
28 }