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

app.ts

37 lines1.0 KB

1import { ChangeDetectionStrategy, Component } from '@angular/core'
2import { createCounter } from './counter'
3import { injectDevtoolsPlugins } from '@tanstack/angular-devtools/provider'
4​
5@Component({
6 selector: 'app-root',
7 template: `
8 <div>
9 <h1>Custom plugins</h1>
10 <h2>Count: {{ counter.value() }}</h2>
11 <div style="display: flex; gap: 4px">
12 <button (click)="increment()">+ increase</button>
13 <button (click)="decrement()">βˆ’ decrease</button>
14 </div>
15​
16 <button (click)="addPlugin()">Add plugin</button>
17 </div>
18 `,
19 changeDetection: ChangeDetectionStrategy.OnPush,
20})
21export class App {
22 readonly counter = createCounter()
23 readonly devtoolsPlugins = injectDevtoolsPlugins()
24​
25 readonly increment = () => this.counter.increment()
26 readonly decrement = () => this.counter.decrement()
27​
28 readonly addPlugin = () => {
29 this.devtoolsPlugins.update((n) => [
30 ...n,
31 {
32 name: `Custom devtools ${n.length + 1}`,
33 render: () => import('./devtools/custom-devtools-panel'),
34 },
35 ])
36 }