Skip to content

Commit 5323064

Browse files
committed
chore: add debugging to docs
1 parent ec60509 commit 5323064

File tree

5 files changed

+57
-26
lines changed

5 files changed

+57
-26
lines changed

docs/framework/react/custom-plugins.md

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,39 +76,33 @@ counter.ts
7676
import { DevtoolsEventClient } from './eventClient.ts'
7777

7878
export function createCounter() {
79-
let count = 0;
80-
const history = [];
79+
let count = 0
80+
const history: Array<number> = []
8181

8282
return {
8383
getCount: () => count,
8484
increment: () => {
85-
const newCount = count++
86-
history.push(count);
85+
history.push(count)
8786

8887
// The emit eventSuffix must match that of the EventMap defined in eventClient.ts
8988
DevtoolsEventClient.emit('counter-state', {
90-
count: newCount
91-
history: history
89+
count: count++,
90+
history: history,
9291
})
93-
94-
count = newCount
9592
},
9693
decrement: () => {
97-
const newCount = count--
98-
history.push(count);
94+
history.push(count)
9995

10096
DevtoolsEventClient.emit('counter-state', {
101-
count: newCount
102-
history: history
97+
count: count--,
98+
history: history,
10399
})
104-
105-
count = newCount
106100
},
107-
};
101+
}
108102
}
109103
```
110104

111-
> **Important** `EventClient` is framework agnostic so this process will be the same regardless of framework or even vanilla in JavaScript.
105+
> **Important** `EventClient` is framework agnostic so this process will be the same regardless of framework or even in vanilla JavaScript.
112106
113107
## Consuming The Event Client
114108

@@ -153,6 +147,7 @@ createRoot(document.getElementById('root')!).render(
153147
<TanstackDevtools
154148
plugins={[
155149
{
150+
// Call it what you like, this is how it will appear in the Menu
156151
name: 'Custom devtools',
157152
render: <DevtoolPanel />,
158153
},
@@ -164,3 +159,40 @@ createRoot(document.getElementById('root')!).render(
164159
```
165160

166161
## Debugging
162+
163+
Both the TansTack `TanstackDevtools` component and the TanStack `EventClient` come with built in debug mode which will log to the console the emitted event as well as the EventClient status.
164+
165+
TanstackDevtool's debugging mode can be activated like so:
166+
```tsx
167+
<TanstackDevtools
168+
eventBusConfig={{ debug: true }}
169+
plugins={[
170+
{
171+
// call it what you like, this is how it will appear in the Menu
172+
name: 'Custom devtools',
173+
render: <DevtoolPanel />,
174+
},
175+
]}
176+
/>
177+
```
178+
179+
Where as the EventClient's debug mode can be activated by:
180+
```tsx
181+
class CustomEventClient extends EventClient<EventMap> {
182+
constructor() {
183+
super({
184+
pluginId: 'custom-devtools',
185+
debug: true,
186+
})
187+
}
188+
}
189+
```
190+
191+
Activating the debug mode will log to the console the current events that emitter has emitted or listened to. The EventClient will have appended `[tanstack-devtools:${pluginId}]` and the client will have appended `[tanstack-devtools:client-bus]`.
192+
193+
Heres an example of both:
194+
```
195+
🌴 [tanstack-devtools:client-bus] Initializing client event bus
196+
197+
🌴 [tanstack-devtools:custom-devtools-plugin] Registered event to bus custom-devtools:counter-state
198+
```

examples/react/custom-devtools/src/App.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ export default function App() {
1919

2020
return (
2121
<div>
22+
<h1>Custom plugins</h1>
2223
<h2>Count: {count}</h2>
23-
<button onClick={increment}>+</button>
24-
<button onClick={decrement}></button>
24+
<div style={{ display: 'grid', gap: '4px' }}>
25+
<button onClick={increment}>+ increase</button>
26+
<button onClick={decrement}>− decrease</button>
27+
</div>
2528
</div>
2629
)
2730
}

examples/react/custom-devtools/src/counter.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,21 @@ export function createCounter() {
77
return {
88
getCount: () => count,
99
increment: () => {
10-
const newCount = count + 1
1110
history.push(count)
1211

1312
// The emit eventSuffix must match that of the EventMap defined in eventClient.ts
1413
DevtoolsEventClient.emit('counter-state', {
15-
count: newCount,
14+
count: count++,
1615
history: history,
1716
})
18-
19-
count = newCount
2017
},
2118
decrement: () => {
22-
const newCount = count - 1
2319
history.push(count)
2420

2521
DevtoolsEventClient.emit('counter-state', {
26-
count: newCount,
22+
count: count--,
2723
history: history,
2824
})
29-
30-
count = newCount
3125
},
3226
}
3327
}

examples/react/custom-devtools/src/eventClient.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class CustomEventClient extends EventClient<EventMap> {
1111
super({
1212
// The pluginId must match that of the event map key
1313
pluginId: 'custom-devtools',
14+
debug: true,
1415
})
1516
}
1617
}

examples/react/custom-devtools/src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ createRoot(document.getElementById('root')!).render(
1010
<App />
1111

1212
<TanstackDevtools
13+
eventBusConfig={{ debug: true }}
1314
plugins={[
1415
{
1516
name: 'Custom devtools',

0 commit comments

Comments
 (0)