Skip to content

Commit

Permalink
feat: button to reset all (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
huang-julien authored Apr 28, 2023
1 parent fe08022 commit ee4e43d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
13 changes: 9 additions & 4 deletions client/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@
<p v-if="!devtools">
awaiting devtools connection
</p>
<div v-else>
<div v-else class="px-2">
<div class="flex">
<NButton @click="rpc.reset()">
Reset
</NButton>
</div>
<RouteList :routes="serverData.routes" />
</div>
</NCard>
</template>

<script setup lang="ts">
import { useDevtoolsClient, onDevtoolsClientConnected } from '@nuxt/devtools-kit/iframe-client'
import { BirpcReturn } from 'birpc'
import { ClientFunctions, ServerData, ServerFunctions } from '~/../src/types'
import { RPC_NAMESPACE } from '~/../src/runtime/utils'
import { ref } from '#imports'
Expand All @@ -29,15 +35,14 @@ const devtools = useDevtoolsClient()
const serverData = ref<ServerData>({
routes: {}
})
let rpc: BirpcReturn<ServerFunctions, ClientFunctions>
onDevtoolsClientConnected(async (client) => {
const rpc = client.devtools.extendClientRpc<ServerFunctions, ClientFunctions>(RPC_NAMESPACE, {
rpc = client.devtools.extendClientRpc<ServerFunctions, ClientFunctions>(RPC_NAMESPACE, {
updateData (data) {
serverData.value = data
}
})
serverData.value = await rpc.getStats()
})
</script>
8 changes: 8 additions & 0 deletions src/runtime/devtools/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ export default function initServer (nuxt: Nuxt) {
return {
routes: routesCount
}
},
reset () {
for (const route in routesCount) {
routesCount[route] = 0
}
rpc.broadcast.updateData({
routes: routesCount
})
}
})

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type ServerData = {
export type ServerFunctions = {
updateStats(route: string): void
getStats(): ServerData
reset(): void
}

export type ClientFunctions = {
Expand Down

0 comments on commit ee4e43d

Please sign in to comment.