@tanstack/query-devtools 5.103.3 → 5.104.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/build/{Devtools-xfqOl5Dl.js → Devtools-BR7-Ww0_.js} +159 -62
  2. package/build/Devtools-BTIH1dw_.js +1238 -0
  3. package/build/Devtools-BTIH1dw_.js.map +1 -0
  4. package/build/{Devtools-XuAvSfeN.cjs → Devtools-DDPb_OXS.cjs} +176 -61
  5. package/build/Devtools-DE6wfpC3.cjs +1237 -0
  6. package/build/DevtoolsComponent-B-JX7seJ.js +2 -0
  7. package/build/DevtoolsComponent-B-JX7seJ.js.map +1 -0
  8. package/build/DevtoolsComponent-DdJdz_3E.cjs +40 -0
  9. package/build/DevtoolsComponent-PDsMk_-d.js +40 -0
  10. package/build/DevtoolsComponent-u_hbjcma.cjs +1 -0
  11. package/build/DevtoolsPanelComponent-CdrNDWsc.js +2 -0
  12. package/build/DevtoolsPanelComponent-CdrNDWsc.js.map +1 -0
  13. package/build/DevtoolsPanelComponent-D7InkRel.cjs +47 -0
  14. package/build/DevtoolsPanelComponent-DWMNAgBe.js +47 -0
  15. package/build/DevtoolsPanelComponent-DyNlv9xD.cjs +1 -0
  16. package/build/dev.cjs +2 -2
  17. package/build/dev.js +2 -2
  18. package/build/index.cjs +1 -1
  19. package/build/index.d.cts +1 -0
  20. package/build/index.d.cts.map +1 -1
  21. package/build/index.d.ts +1 -0
  22. package/build/index.d.ts.map +1 -1
  23. package/build/index.js +1 -1
  24. package/package.json +8 -8
  25. package/src/Devtools.tsx +62 -82
  26. package/src/DevtoolsComponent.tsx +17 -5
  27. package/src/DevtoolsPanelComponent.tsx +23 -14
  28. package/src/contexts/DevtoolsOfflineContext.ts +10 -0
  29. package/src/contexts/DevtoolsStateContext.ts +10 -0
  30. package/src/contexts/DevtoolsSubscriptionsContext.ts +11 -0
  31. package/src/contexts/types.ts +37 -1
  32. package/src/createCacheSubscriptionRegistry.ts +40 -0
  33. package/src/providers/DevtoolsOfflineProvider.tsx +31 -0
  34. package/src/providers/DevtoolsStateProvider.tsx +28 -0
  35. package/src/providers/DevtoolsSubscriptionsProvider.tsx +30 -0
  36. package/build/Devtools-DP9QP4ya.cjs +0 -1237
  37. package/build/Devtools-DpIxfOum.js +0 -1238
  38. package/build/Devtools-DpIxfOum.js.map +0 -1
  39. package/build/DevtoolsComponent-BEFw32kp.js +0 -2
  40. package/build/DevtoolsComponent-BEFw32kp.js.map +0 -1
  41. package/build/DevtoolsComponent-DRjJuLRU.js +0 -34
  42. package/build/DevtoolsComponent-DjkCvfLf.cjs +0 -34
  43. package/build/DevtoolsComponent-bl_b_SFT.cjs +0 -1
  44. package/build/DevtoolsPanelComponent-BE6hbJd6.js +0 -2
  45. package/build/DevtoolsPanelComponent-BE6hbJd6.js.map +0 -1
  46. package/build/DevtoolsPanelComponent-BTfH8T_h.cjs +0 -41
  47. package/build/DevtoolsPanelComponent-CkmpODyJ.js +0 -41
  48. package/build/DevtoolsPanelComponent-DfaRC3RE.cjs +0 -1
package/src/Devtools.tsx CHANGED
@@ -17,6 +17,9 @@ import { Key } from '@solid-primitives/keyed'
17
17
  import { createResizeObserver } from '@solid-primitives/resize-observer'
18
18
  import { DropdownMenu, RadioGroup } from '@kobalte/core'
19
19
  import { Portal } from 'solid-js/web'
20
+ import { useDevtoolsOffline } from './contexts/DevtoolsOfflineContext'
21
+ import { useDevtoolsSubscriptions } from './contexts/DevtoolsSubscriptionsContext'
22
+ import { useDevtoolsState } from './contexts/DevtoolsStateContext'
20
23
  import { tokens } from './theme'
21
24
  import {
22
25
  convertRemToPixels,
@@ -78,7 +81,7 @@ import type {
78
81
  QueryCacheNotifyEvent,
79
82
  } from '@tanstack/query-core'
80
83
  import type { StorageObject, StorageSetter } from '@solid-primitives/storage'
81
- import type { Accessor, Component, JSX, Setter } from 'solid-js'
84
+ import type { Accessor, Component, JSX } from 'solid-js'
82
85
 
83
86
  interface DevtoolsPanelProps {
84
87
  localStore: StorageObject<string>
@@ -98,15 +101,6 @@ interface QueryStatusProps {
98
101
  count: number
99
102
  }
100
103
 
101
- const [selectedQueryHash, setSelectedQueryHash] = createSignal<string | null>(
102
- null,
103
- )
104
- const [selectedMutationId, setSelectedMutationId] = createSignal<number | null>(
105
- null,
106
- )
107
- const [panelWidth, setPanelWidth] = createSignal(0)
108
- const [offline, setOffline] = createSignal(false)
109
-
110
104
  export type DevtoolsComponentType = Component<QueryDevtoolsProps> & {
111
105
  shadowDOMTarget?: ShadowRoot
112
106
  }
@@ -119,19 +113,6 @@ export const Devtools: Component<DevtoolsPanelProps> = (props) => {
119
113
  const styles = createMemo(() => {
120
114
  return theme() === 'dark' ? darkStyles(css) : lightStyles(css)
121
115
  })
122
- const onlineManager = createMemo(
123
- () => useQueryDevtoolsContext().onlineManager,
124
- )
125
- onMount(() => {
126
- const unsubscribe = onlineManager().subscribe((online) => {
127
- setOffline(!online)
128
- })
129
-
130
- onCleanup(() => {
131
- unsubscribe()
132
- })
133
- })
134
-
135
116
  const pip = usePiPWindow()
136
117
 
137
118
  const buttonPosition = createMemo(() => {
@@ -285,6 +266,8 @@ export const Devtools: Component<DevtoolsPanelProps> = (props) => {
285
266
  const PiPPanel: Component<{
286
267
  children: JSX.Element
287
268
  }> = (props) => {
269
+ const { panelWidth, setPanelWidth } = useDevtoolsState()
270
+
288
271
  const pip = usePiPWindow()
289
272
  const theme = useTheme()
290
273
  const css = useQueryDevtoolsContext().shadowDOMTarget
@@ -355,6 +338,8 @@ const PiPPanel: Component<{
355
338
  export const ParentPanel: Component<{
356
339
  children: JSX.Element
357
340
  }> = (props) => {
341
+ const { panelWidth, setPanelWidth } = useDevtoolsState()
342
+
358
343
  const theme = useTheme()
359
344
  const css = useQueryDevtoolsContext().shadowDOMTarget
360
345
  ? goober.css.bind({ target: useQueryDevtoolsContext().shadowDOMTarget })
@@ -412,6 +397,8 @@ export const ParentPanel: Component<{
412
397
  }
413
398
 
414
399
  const DraggablePanel: Component<DevtoolsPanelProps> = (props) => {
400
+ const { setSelectedQueryHash, panelWidth, setPanelWidth } = useDevtoolsState()
401
+
415
402
  const theme = useTheme()
416
403
  const css = useQueryDevtoolsContext().shadowDOMTarget
417
404
  ? goober.css.bind({ target: useQueryDevtoolsContext().shadowDOMTarget })
@@ -676,6 +663,16 @@ const DraggablePanel: Component<DevtoolsPanelProps> = (props) => {
676
663
  }
677
664
 
678
665
  export const ContentView: Component<ContentViewProps> = (props) => {
666
+ const {
667
+ selectedQueryHash,
668
+ setSelectedQueryHash,
669
+ selectedMutationId,
670
+ setSelectedMutationId,
671
+ panelWidth,
672
+ } = useDevtoolsState()
673
+
674
+ const { offline, toggleOffline } = useDevtoolsOffline()
675
+
679
676
  setupQueryCacheSubscription()
680
677
  setupMutationCacheSubscription()
681
678
  let containerRef!: HTMLDivElement
@@ -710,10 +707,6 @@ export const ContentView: Component<ContentViewProps> = (props) => {
710
707
  () => mutationSortFns[mutationSort() as string],
711
708
  )
712
709
 
713
- const onlineManager = createMemo(
714
- () => useQueryDevtoolsContext().onlineManager,
715
- )
716
-
717
710
  const query_cache = createMemo(() => {
718
711
  return useQueryDevtoolsContext().client.getQueryCache()
719
712
  })
@@ -1035,9 +1028,7 @@ export const ContentView: Component<ContentViewProps> = (props) => {
1035
1028
  <Trash />
1036
1029
  </button>
1037
1030
  <button
1038
- onClick={() => {
1039
- onlineManager().setOnline(!onlineManager().isOnline())
1040
- }}
1031
+ onClick={toggleOffline}
1041
1032
  class={cx(
1042
1033
  styles().actionsBtn,
1043
1034
  offline() && styles().actionsBtnOffline,
@@ -1376,6 +1367,8 @@ export const ContentView: Component<ContentViewProps> = (props) => {
1376
1367
  }
1377
1368
 
1378
1369
  const QueryRow: Component<{ query: Query }> = (props) => {
1370
+ const { selectedQueryHash, setSelectedQueryHash } = useDevtoolsState()
1371
+
1379
1372
  const theme = useTheme()
1380
1373
  const css = useQueryDevtoolsContext().shadowDOMTarget
1381
1374
  ? goober.css.bind({ target: useQueryDevtoolsContext().shadowDOMTarget })
@@ -1485,6 +1478,8 @@ const QueryRow: Component<{ query: Query }> = (props) => {
1485
1478
  }
1486
1479
 
1487
1480
  const MutationRow: Component<{ mutation: Mutation }> = (props) => {
1481
+ const { selectedMutationId, setSelectedMutationId } = useDevtoolsState()
1482
+
1488
1483
  const theme = useTheme()
1489
1484
  const css = useQueryDevtoolsContext().shadowDOMTarget
1490
1485
  ? goober.css.bind({ target: useQueryDevtoolsContext().shadowDOMTarget })
@@ -1726,6 +1721,8 @@ const MutationStatusCount: Component = () => {
1726
1721
  }
1727
1722
 
1728
1723
  const QueryStatus: Component<QueryStatusProps> = (props) => {
1724
+ const { selectedQueryHash, panelWidth } = useDevtoolsState()
1725
+
1729
1726
  const theme = useTheme()
1730
1727
  const css = useQueryDevtoolsContext().shadowDOMTarget
1731
1728
  ? goober.css.bind({ target: useQueryDevtoolsContext().shadowDOMTarget })
@@ -1841,6 +1838,8 @@ const QueryStatus: Component<QueryStatusProps> = (props) => {
1841
1838
  }
1842
1839
 
1843
1840
  const QueryDetails = () => {
1841
+ const { selectedQueryHash, setSelectedQueryHash } = useDevtoolsState()
1842
+
1844
1843
  const theme = useTheme()
1845
1844
  const css = useQueryDevtoolsContext().shadowDOMTarget
1846
1845
  ? goober.css.bind({ target: useQueryDevtoolsContext().shadowDOMTarget })
@@ -2386,6 +2385,8 @@ const QueryDetails = () => {
2386
2385
  }
2387
2386
 
2388
2387
  const MutationDetails = () => {
2388
+ const { selectedMutationId } = useDevtoolsState()
2389
+
2389
2390
  const theme = useTheme()
2390
2391
  const css = useQueryDevtoolsContext().shadowDOMTarget
2391
2392
  ? goober.css.bind({ target: useQueryDevtoolsContext().shadowDOMTarget })
@@ -2573,35 +2574,22 @@ const MutationDetails = () => {
2573
2574
  )
2574
2575
  }
2575
2576
 
2576
- const queryCacheMap = new Map<
2577
- (q: Accessor<QueryCache>) => any,
2578
- {
2579
- setter: Setter<any>
2580
- shouldUpdate: (event: QueryCacheNotifyEvent) => boolean
2581
- }
2582
- >()
2583
-
2584
2577
  const setupQueryCacheSubscription = () => {
2578
+ const { queryCacheSubscriptions } = useDevtoolsSubscriptions()
2585
2579
  const queryCache = createMemo(() => {
2586
2580
  const client = useQueryDevtoolsContext().client
2587
2581
  return client.getQueryCache()
2588
2582
  })
2589
2583
 
2590
- const unsubscribe = queryCache().subscribe((q) => {
2591
- batch(() => {
2592
- for (const [callback, value] of queryCacheMap.entries()) {
2593
- if (!value.shouldUpdate(q)) continue
2594
- value.setter(callback(queryCache))
2595
- }
2584
+ createEffect(() => {
2585
+ const cache = queryCache()
2586
+ const unsubscribe = cache.subscribe((event) => {
2587
+ batch(() => {
2588
+ queryCacheSubscriptions.notify(() => cache, event)
2589
+ })
2596
2590
  })
2591
+ onCleanup(unsubscribe)
2597
2592
  })
2598
-
2599
- onCleanup(() => {
2600
- queryCacheMap.clear()
2601
- unsubscribe()
2602
- })
2603
-
2604
- return unsubscribe
2605
2593
  }
2606
2594
 
2607
2595
  const createSubscribeToQueryCacheBatcher = <T,>(
@@ -2609,6 +2597,7 @@ const createSubscribeToQueryCacheBatcher = <T,>(
2609
2597
  equalityCheck: boolean = true,
2610
2598
  shouldUpdate: (event: QueryCacheNotifyEvent) => boolean = () => true,
2611
2599
  ) => {
2600
+ const { queryCacheSubscriptions } = useDevtoolsSubscriptions()
2612
2601
  const queryCache = createMemo(() => {
2613
2602
  const client = useQueryDevtoolsContext().client
2614
2603
  return client.getQueryCache()
@@ -2623,49 +2612,44 @@ const createSubscribeToQueryCacheBatcher = <T,>(
2623
2612
  setValue(callback(queryCache))
2624
2613
  })
2625
2614
 
2626
- queryCacheMap.set(callback, {
2627
- setter: setValue,
2628
- shouldUpdate: shouldUpdate,
2629
- })
2630
-
2631
- onCleanup(() => {
2632
- queryCacheMap.delete(callback)
2633
- })
2615
+ queryCacheSubscriptions.register(callback, setValue, shouldUpdate)
2634
2616
 
2635
2617
  return value
2636
2618
  }
2637
2619
 
2638
- const mutationCacheMap = new Map<
2639
- (q: Accessor<MutationCache>) => any,
2640
- Setter<any>
2641
- >()
2642
-
2643
2620
  const setupMutationCacheSubscription = () => {
2621
+ const { mutationCacheSubscriptions } = useDevtoolsSubscriptions()
2644
2622
  const mutationCache = createMemo(() => {
2645
2623
  const client = useQueryDevtoolsContext().client
2646
2624
  return client.getMutationCache()
2647
2625
  })
2648
2626
 
2649
- const unsubscribe = mutationCache().subscribe(() => {
2650
- for (const [callback, setter] of mutationCacheMap.entries()) {
2651
- queueMicrotask(() => {
2652
- setter(callback(mutationCache))
2653
- })
2654
- }
2655
- })
2656
-
2657
- onCleanup(() => {
2658
- mutationCacheMap.clear()
2659
- unsubscribe()
2627
+ createEffect(() => {
2628
+ const cache = mutationCache()
2629
+ let active = true
2630
+ const unsubscribe = cache.subscribe((event) => {
2631
+ mutationCacheSubscriptions.notify(
2632
+ () => cache,
2633
+ event,
2634
+ (update) => {
2635
+ queueMicrotask(() => {
2636
+ if (active) update()
2637
+ })
2638
+ },
2639
+ )
2640
+ })
2641
+ onCleanup(() => {
2642
+ active = false
2643
+ unsubscribe()
2644
+ })
2660
2645
  })
2661
-
2662
- return unsubscribe
2663
2646
  }
2664
2647
 
2665
2648
  const createSubscribeToMutationCacheBatcher = <T,>(
2666
2649
  callback: (queryCache: Accessor<MutationCache>) => Exclude<T, Function>,
2667
2650
  equalityCheck: boolean = true,
2668
2651
  ) => {
2652
+ const { mutationCacheSubscriptions } = useDevtoolsSubscriptions()
2669
2653
  const mutationCache = createMemo(() => {
2670
2654
  const client = useQueryDevtoolsContext().client
2671
2655
  return client.getMutationCache()
@@ -2680,11 +2664,7 @@ const createSubscribeToMutationCacheBatcher = <T,>(
2680
2664
  setValue(callback(mutationCache))
2681
2665
  })
2682
2666
 
2683
- mutationCacheMap.set(callback, setValue)
2684
-
2685
- onCleanup(() => {
2686
- mutationCacheMap.delete(callback)
2687
- })
2667
+ mutationCacheSubscriptions.register(callback, setValue)
2688
2668
 
2689
2669
  return value
2690
2670
  }
@@ -1,5 +1,8 @@
1
1
  import { createLocalStorage } from '@solid-primitives/storage'
2
2
  import { createMemo } from 'solid-js'
3
+ import { DevtoolsOfflineProvider } from './providers/DevtoolsOfflineProvider'
4
+ import { DevtoolsSubscriptionsProvider } from './providers/DevtoolsSubscriptionsProvider'
5
+ import { DevtoolsStateProvider } from './providers/DevtoolsStateProvider'
3
6
  import { Devtools } from './Devtools'
4
7
  import { getPreferredColorScheme } from './utils'
5
8
  import { THEME_PREFERENCE } from './constants'
@@ -24,11 +27,20 @@ const DevtoolsComponent: DevtoolsComponentType = (props) => {
24
27
 
25
28
  return (
26
29
  <QueryDevtoolsContext.Provider value={props}>
27
- <PiPProvider localStore={localStore} setLocalStore={setLocalStore}>
28
- <ThemeContext.Provider value={theme}>
29
- <Devtools localStore={localStore} setLocalStore={setLocalStore} />
30
- </ThemeContext.Provider>
31
- </PiPProvider>
30
+ <DevtoolsStateProvider>
31
+ <DevtoolsOfflineProvider>
32
+ <DevtoolsSubscriptionsProvider>
33
+ <PiPProvider localStore={localStore} setLocalStore={setLocalStore}>
34
+ <ThemeContext.Provider value={theme}>
35
+ <Devtools
36
+ localStore={localStore}
37
+ setLocalStore={setLocalStore}
38
+ />
39
+ </ThemeContext.Provider>
40
+ </PiPProvider>
41
+ </DevtoolsSubscriptionsProvider>
42
+ </DevtoolsOfflineProvider>
43
+ </DevtoolsStateProvider>
32
44
  </QueryDevtoolsContext.Provider>
33
45
  )
34
46
  }
@@ -1,5 +1,8 @@
1
1
  import { createLocalStorage } from '@solid-primitives/storage'
2
2
  import { createMemo } from 'solid-js'
3
+ import { DevtoolsOfflineProvider } from './providers/DevtoolsOfflineProvider'
4
+ import { DevtoolsSubscriptionsProvider } from './providers/DevtoolsSubscriptionsProvider'
5
+ import { DevtoolsStateProvider } from './providers/DevtoolsStateProvider'
3
6
  import { ContentView, ParentPanel } from './Devtools'
4
7
  import { getPreferredColorScheme } from './utils'
5
8
  import { THEME_PREFERENCE } from './constants'
@@ -24,22 +27,28 @@ const DevtoolsPanelComponent: DevtoolsComponentType = (props) => {
24
27
 
25
28
  return (
26
29
  <QueryDevtoolsContext.Provider value={props}>
27
- <PiPProvider
28
- disabled
29
- localStore={localStore}
30
- setLocalStore={setLocalStore}
31
- >
32
- <ThemeContext.Provider value={theme}>
33
- <ParentPanel>
34
- <ContentView
30
+ <DevtoolsStateProvider>
31
+ <DevtoolsOfflineProvider>
32
+ <DevtoolsSubscriptionsProvider>
33
+ <PiPProvider
34
+ disabled
35
35
  localStore={localStore}
36
36
  setLocalStore={setLocalStore}
37
- onClose={props.onClose}
38
- showPanelViewOnly
39
- />
40
- </ParentPanel>
41
- </ThemeContext.Provider>
42
- </PiPProvider>
37
+ >
38
+ <ThemeContext.Provider value={theme}>
39
+ <ParentPanel>
40
+ <ContentView
41
+ localStore={localStore}
42
+ setLocalStore={setLocalStore}
43
+ onClose={props.onClose}
44
+ showPanelViewOnly
45
+ />
46
+ </ParentPanel>
47
+ </ThemeContext.Provider>
48
+ </PiPProvider>
49
+ </DevtoolsSubscriptionsProvider>
50
+ </DevtoolsOfflineProvider>
51
+ </DevtoolsStateProvider>
43
52
  </QueryDevtoolsContext.Provider>
44
53
  )
45
54
  }
@@ -0,0 +1,10 @@
1
+ import { createContext, useContext } from 'solid-js'
2
+ import type { DevtoolsOfflineState } from './types'
3
+
4
+ export const DevtoolsOfflineContext = createContext<DevtoolsOfflineState>()
5
+
6
+ export function useDevtoolsOffline() {
7
+ const state = useContext(DevtoolsOfflineContext)
8
+ if (!state) throw new Error('Missing DevtoolsOfflineProvider')
9
+ return state
10
+ }
@@ -0,0 +1,10 @@
1
+ import { createContext, useContext } from 'solid-js'
2
+ import type { DevtoolsState } from './types'
3
+
4
+ export const DevtoolsStateContext = createContext<DevtoolsState>()
5
+
6
+ export function useDevtoolsState() {
7
+ const state = useContext(DevtoolsStateContext)
8
+ if (!state) throw new Error('Missing DevtoolsStateProvider')
9
+ return state
10
+ }
@@ -0,0 +1,11 @@
1
+ import { createContext, useContext } from 'solid-js'
2
+ import type { DevtoolsSubscriptions } from './types'
3
+
4
+ export const DevtoolsSubscriptionsContext =
5
+ createContext<DevtoolsSubscriptions>()
6
+
7
+ export function useDevtoolsSubscriptions() {
8
+ const subscriptions = useContext(DevtoolsSubscriptionsContext)
9
+ if (!subscriptions) throw new Error('Missing DevtoolsSubscriptionsProvider')
10
+ return subscriptions
11
+ }
@@ -1,4 +1,14 @@
1
- import type { Query, QueryClient, onlineManager } from '@tanstack/query-core'
1
+ import type {
2
+ MutationCache,
3
+ MutationCacheNotifyEvent,
4
+ Query,
5
+ QueryCache,
6
+ QueryCacheNotifyEvent,
7
+ QueryClient,
8
+ onlineManager,
9
+ } from '@tanstack/query-core'
10
+ import type { Accessor, Setter } from 'solid-js'
11
+ import type { createCacheSubscriptionRegistry } from '../createCacheSubscriptionRegistry'
2
12
 
3
13
  type XPosition = 'left' | 'right'
4
14
  type YPosition = 'top' | 'bottom'
@@ -33,3 +43,29 @@ export interface QueryDevtoolsProps {
33
43
  hideDisabledQueries?: boolean
34
44
  theme?: Theme
35
45
  }
46
+
47
+ export interface DevtoolsState {
48
+ selectedQueryHash: Accessor<string | null>
49
+ setSelectedQueryHash: Setter<string | null>
50
+ selectedMutationId: Accessor<number | null>
51
+ setSelectedMutationId: Setter<number | null>
52
+ panelWidth: Accessor<number>
53
+ setPanelWidth: Setter<number>
54
+ }
55
+
56
+ export interface DevtoolsSubscriptions {
57
+ queryCacheSubscriptions: ReturnType<
58
+ typeof createCacheSubscriptionRegistry<QueryCache, QueryCacheNotifyEvent>
59
+ >
60
+ mutationCacheSubscriptions: ReturnType<
61
+ typeof createCacheSubscriptionRegistry<
62
+ MutationCache,
63
+ MutationCacheNotifyEvent
64
+ >
65
+ >
66
+ }
67
+
68
+ export interface DevtoolsOfflineState {
69
+ offline: Accessor<boolean>
70
+ toggleOffline: () => void
71
+ }
@@ -0,0 +1,40 @@
1
+ import { onCleanup } from 'solid-js'
2
+ import type { Accessor, Setter } from 'solid-js'
3
+
4
+ export function createCacheSubscriptionRegistry<TCache, TEvent>() {
5
+ const subscriptions = new Map<
6
+ symbol,
7
+ {
8
+ shouldUpdate: (event: TEvent) => boolean
9
+ update: (cache: Accessor<TCache>) => void
10
+ }
11
+ >()
12
+
13
+ function register<T>(
14
+ callback: (cache: Accessor<TCache>) => Exclude<T, Function>,
15
+ setter: Setter<T>,
16
+ shouldUpdate: (event: TEvent) => boolean = () => true,
17
+ ) {
18
+ const id = Symbol()
19
+ subscriptions.set(id, {
20
+ shouldUpdate,
21
+ update: (cache) => setter(callback(cache)),
22
+ })
23
+ onCleanup(() => subscriptions.delete(id))
24
+ }
25
+
26
+ function notify(
27
+ cache: Accessor<TCache>,
28
+ event: TEvent,
29
+ schedule: (update: () => void) => void = (update) => update(),
30
+ ) {
31
+ for (const [id, subscription] of subscriptions) {
32
+ if (!subscription.shouldUpdate(event)) continue
33
+ schedule(() => {
34
+ if (subscriptions.has(id)) subscription.update(cache)
35
+ })
36
+ }
37
+ }
38
+
39
+ return { register, notify }
40
+ }
@@ -0,0 +1,31 @@
1
+ import { createEffect, createSignal, onCleanup } from 'solid-js'
2
+ import { useQueryDevtoolsContext } from '../contexts/QueryDevtoolsContext'
3
+ import { DevtoolsOfflineContext } from '../contexts/DevtoolsOfflineContext'
4
+ import type { DevtoolsOfflineState } from '../contexts/types'
5
+ import type { ParentProps } from 'solid-js'
6
+
7
+ export function DevtoolsOfflineProvider(props: ParentProps) {
8
+ const [offline, setOffline] = createSignal(false)
9
+ const context = useQueryDevtoolsContext()
10
+
11
+ createEffect(() => {
12
+ const manager = context.onlineManager
13
+ setOffline(!manager.isOnline())
14
+ const unsubscribe = manager.subscribe((online) => setOffline(!online))
15
+ onCleanup(unsubscribe)
16
+ })
17
+
18
+ const state: DevtoolsOfflineState = {
19
+ offline,
20
+ toggleOffline: () => {
21
+ const manager = context.onlineManager
22
+ manager.setOnline(!manager.isOnline())
23
+ },
24
+ }
25
+
26
+ return (
27
+ <DevtoolsOfflineContext.Provider value={state}>
28
+ {props.children}
29
+ </DevtoolsOfflineContext.Provider>
30
+ )
31
+ }
@@ -0,0 +1,28 @@
1
+ import { createSignal } from 'solid-js'
2
+ import { DevtoolsStateContext } from '../contexts/DevtoolsStateContext'
3
+ import type { DevtoolsState } from '../contexts/types'
4
+ import type { ParentProps } from 'solid-js'
5
+
6
+ export function DevtoolsStateProvider(props: ParentProps) {
7
+ const [selectedQueryHash, setSelectedQueryHash] = createSignal<string | null>(
8
+ null,
9
+ )
10
+ const [selectedMutationId, setSelectedMutationId] = createSignal<
11
+ number | null
12
+ >(null)
13
+ const [panelWidth, setPanelWidth] = createSignal(0)
14
+
15
+ const state: DevtoolsState = {
16
+ selectedQueryHash,
17
+ setSelectedQueryHash,
18
+ selectedMutationId,
19
+ setSelectedMutationId,
20
+ panelWidth,
21
+ setPanelWidth,
22
+ }
23
+ return (
24
+ <DevtoolsStateContext.Provider value={state}>
25
+ {props.children}
26
+ </DevtoolsStateContext.Provider>
27
+ )
28
+ }
@@ -0,0 +1,30 @@
1
+ import { createCacheSubscriptionRegistry } from '../createCacheSubscriptionRegistry'
2
+ import { DevtoolsSubscriptionsContext } from '../contexts/DevtoolsSubscriptionsContext'
3
+ import type {
4
+ MutationCache,
5
+ MutationCacheNotifyEvent,
6
+ QueryCache,
7
+ QueryCacheNotifyEvent,
8
+ } from '@tanstack/query-core'
9
+ import type { DevtoolsSubscriptions } from '../contexts/types'
10
+ import type { ParentProps } from 'solid-js'
11
+
12
+ export function DevtoolsSubscriptionsProvider(props: ParentProps) {
13
+ const queryCacheSubscriptions = createCacheSubscriptionRegistry<
14
+ QueryCache,
15
+ QueryCacheNotifyEvent
16
+ >()
17
+ const mutationCacheSubscriptions = createCacheSubscriptionRegistry<
18
+ MutationCache,
19
+ MutationCacheNotifyEvent
20
+ >()
21
+ const subscriptions: DevtoolsSubscriptions = {
22
+ queryCacheSubscriptions,
23
+ mutationCacheSubscriptions,
24
+ }
25
+ return (
26
+ <DevtoolsSubscriptionsContext.Provider value={subscriptions}>
27
+ {props.children}
28
+ </DevtoolsSubscriptionsContext.Provider>
29
+ )
30
+ }