MCPcopy Create free account
hub / github.com/TanStack/devtools / createCounter

Function createCounter

examples/angular/basic/src/app/counter.ts:4–30  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

AppClass · 0.90

Calls 3

countFunction · 0.85
updateMethod · 0.80
emitMethod · 0.45

Tested by

no test coverage detected