Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: button to reset all #10

Merged
merged 1 commit into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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