| 1 | import { DevtoolsEventClient } from './eventClient.ts' |
| 2 | |
| 3 | export 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 | } |
| 29 | } |