-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoid using top-level await, fix #723
- Loading branch information
Showing
17 changed files
with
201 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,36 @@ | ||
import type { ToRefs } from 'vue' | ||
import type { NuxtDevToolsOptions } from '../../types' | ||
import { toRefs, watchDebounced } from '@vueuse/core' | ||
import { ref } from 'vue' | ||
import { watchDebounced } from '@vueuse/core' | ||
import { toRefs } from 'vue' | ||
import { defaultTabOptions } from '../../src/constant' | ||
import { rpc } from './rpc' | ||
|
||
let instance: ReturnType<typeof init> | null = null | ||
const cache = new Map<string, any>() | ||
|
||
function init() { | ||
// Assets | ||
const assetsOptions = ref<NuxtDevToolsOptions['assets']>(defaultTabOptions.assets) | ||
rpc.getOptions('assets').then((options) => { | ||
assetsOptions.value = options | ||
}) | ||
const assets = toRefs(assetsOptions) | ||
|
||
watchDebounced(assetsOptions, async (options) => { | ||
rpc.updateOptions('assets', options) | ||
}, { deep: true, flush: 'post', debounce: 500, maxWait: 1000 }) | ||
|
||
// Server Routes | ||
const serverRouteOptions = ref<NuxtDevToolsOptions['serverRoutes']>(defaultTabOptions.serverRoutes) | ||
rpc.getOptions('serverRoutes').then((options) => { | ||
serverRouteOptions.value = options | ||
}) | ||
const serverRoutes = toRefs(serverRouteOptions) | ||
|
||
watchDebounced(serverRouteOptions, async (options) => { | ||
rpc.updateOptions('serverRoutes', options) | ||
}, { deep: true, flush: 'post', debounce: 500, maxWait: 1000 }) | ||
|
||
// Server Tasks | ||
const serverTasksOptions = ref<NuxtDevToolsOptions['serverTasks']>(defaultTabOptions.serverTasks) | ||
rpc.getOptions('serverTasks').then((options) => { | ||
serverTasksOptions.value = options | ||
}) | ||
const serverTasks = toRefs(serverTasksOptions) | ||
|
||
watchDebounced(serverTasksOptions, async (options) => { | ||
rpc.updateOptions('serverTasks', options) | ||
}, { deep: true, flush: 'post', debounce: 500, maxWait: 1000 }) | ||
|
||
// Options List | ||
const list = { | ||
serverRoutes, | ||
serverTasks, | ||
assets, | ||
function getTabOptions<T extends keyof NuxtDevToolsOptions>(tab: T): ToRefs<NuxtDevToolsOptions[T]> { | ||
if (cache.has(tab)) { | ||
return cache.get(tab) | ||
} | ||
|
||
return list | ||
const source = reactive({ ...defaultTabOptions[tab] }) as NuxtDevToolsOptions[T] | ||
const refs = toRefs(source) | ||
cache.set(tab, refs) | ||
|
||
rpc.getOptions(tab) | ||
.then((options) => { | ||
Object.assign(source, options) | ||
|
||
watchDebounced( | ||
source, | ||
async (options) => { | ||
rpc.updateOptions(tab, options) | ||
}, | ||
{ deep: true, flush: 'post', debounce: 500, maxWait: 1000 }, | ||
) | ||
}) | ||
|
||
return refs | ||
} | ||
|
||
export function useDevToolsOptions<T extends keyof ReturnType<typeof init>>(tab: T) { | ||
if (!instance) { | ||
instance = init() | ||
} | ||
return instance[tab] | ||
export function useDevToolsOptions<T extends keyof NuxtDevToolsOptions>(tab: T): ToRefs<NuxtDevToolsOptions[T]> { | ||
return getTabOptions(tab) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<template> | ||
<div> | ||
<div relative w-full> | ||
<slot /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.