File tree Expand file tree Collapse file tree 5 files changed +32
-7
lines changed
Expand file tree Collapse file tree 5 files changed +32
-7
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,8 @@ const tab = useLocalStorage('rstore-devtools-tab', '0')
2626const currentTab = computed (() => tabs [Number .parseInt (tab .value )]! )
2727
2828const cache = useStoreCache ()
29+
30+ const showCacheOps = useLocalStorage (' rstore-devtools-show-cache-ops' , false )
2931 </script >
3032
3133<template >
@@ -44,8 +46,15 @@ const cache = useStoreCache()
4446 }"
4547 />
4648
47- <div class =" flex-1 flex justify-end items-center gap-1 " >
49+ <div class =" flex-1 flex justify-end items-center gap-2 " >
4850 <template v-if =" currentTab .slot === ' history' " >
51+ <USwitch
52+ v-model =" showCacheOps"
53+ size =" xs"
54+ label =" Cache"
55+ class =" text-xs"
56+ />
57+
4958 <UTooltip text =" Clear history" >
5059 <UButton
5160 icon =" lucide:trash"
@@ -70,7 +79,7 @@ const cache = useStoreCache()
7079 <template v-if =" currentTab .slot === ' history' " >
7180 <div class =" flex flex-col-reverse p-1 gap-1" >
7281 <DevtoolsHistoryItem
73- v-for =" (item, index) in stats.store"
82+ v-for =" (item, index) in showCacheOps ? stats.store : stats.store.filter((item) => !item.operation.startsWith('cache')) "
7483 :key =" index"
7584 :item
7685 />
Original file line number Diff line number Diff line change @@ -3,8 +3,11 @@ const props = defineProps<{
33 item: StoreHistoryItem
44}>()
55
6- const startedAgo = useTimeAgo (() => props .item .started )
6+ const startedAgo = useTimeAgo (() => props .item .started ?? props . item . ended )
77const duration = computed (() => {
8+ if (! props .item .started ) {
9+ return null
10+ }
811 const diff = props .item .ended .getTime () - props .item .started .getTime ()
912 return diff < 1000 ? ` ${diff }ms ` : ` ${(diff / 1000 ).toFixed (2 )}s `
1013})
@@ -15,6 +18,7 @@ const icons = {
1518 create: ' lucide:plus' ,
1619 update: ' lucide:pen' ,
1720 delete: ' lucide:trash' ,
21+ cacheWrite: ' lucide:database' ,
1822}
1923 </script >
2024
@@ -95,7 +99,7 @@ const icons = {
9599 </div >
96100 <div class =" flex items-baseline gap-2 pt-0.5 pr-0.5" >
97101 <span class =" opacity-50 font-sans" >{{ startedAgo }}</span >
98- <span >{{ duration }}</span >
102+ <span v-if = " duration " >{{ duration }}</span >
99103 </div >
100104 </div >
101105 </div >
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { useDevtoolsClient } from '@nuxt/devtools-kit/iframe-client'
33export function useStoreStats ( ) {
44 const client = useDevtoolsClient ( )
55
6- const stats = computed ( ( ) => client . value ?. host . nuxt . $rstoreDevtoolsStats ( ) )
6+ const stats = computed ( ( ) => client . value ?. host . nuxt . $rstoreDevtoolsStats ( ) as { store : StoreHistoryItem [ ] } )
77
88 client . value ?. host . nuxt . $rstoreHistoryUpdated ?. on ( ( ) => {
99 triggerRef ( stats )
Original file line number Diff line number Diff line change 11import type { FindOptions } from '@rstore/shared'
22
33export interface StoreHistoryItem {
4- operation : 'fetchFirst' | 'fetchMany' | 'create' | 'update' | 'delete'
4+ operation : 'fetchFirst' | 'fetchMany' | 'create' | 'update' | 'delete' | 'cacheWrite'
55 model : string
66 key ?: string
77 findOptions ?: FindOptions < any , any , any >
88 item ?: any
99 result : any
10- started : Date
10+ started ? : Date | undefined
1111 ended : Date
1212 server ?: boolean
1313}
Original file line number Diff line number Diff line change @@ -99,6 +99,18 @@ export const devtoolsPlugin = definePlugin({
9999 historyUpdated . trigger ( )
100100 }
101101 } )
102+
103+ hook ( 'afterCacheWrite' , ( payload ) => {
104+ storeStats . value . store . push ( {
105+ operation : 'cacheWrite' ,
106+ model : payload . model . name ,
107+ ended : new Date ( ) ,
108+ result : payload . result ,
109+ key : payload . key ,
110+ server : import . meta. server ,
111+ } )
112+ historyUpdated . trigger ( )
113+ } )
102114 } ,
103115} )
104116
You can’t perform that action at this time.
0 commit comments