File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { getCurrentInstance , watch } from 'vue'
1+ import {
2+ effectScope ,
3+ getCurrentInstance ,
4+ getCurrentScope ,
5+ onScopeDispose ,
6+ watch ,
7+ } from 'vue'
28import { remove , upsert } from './registry'
39import type { VuebuggerEntry } from './types'
410
@@ -16,28 +22,33 @@ export function debug<T extends Record<string, any>>(
1622 'No component'
1723 const uid = `${ componentName } /${ groupId } -${ Math . random ( ) . toString ( 36 ) . slice ( 2 , 9 ) } `
1824
19- watch (
20- ( ) => state ,
21- ( value , _ , onCleanup ) => {
22- upsert ( {
25+ const scope = getCurrentScope ( ) ?? effectScope ( )
26+ scope . run ( ( ) => {
27+ onScopeDispose ( ( ) =>
28+ remove ( {
2329 groupId,
2430 uid,
2531 componentName,
2632 componentInstance : instance ,
27- debugState : value ,
28- } )
29- onCleanup ( ( ) => {
30- remove ( {
33+ debugState : state ,
34+ } ) ,
35+ )
36+ watch (
37+ ( ) => state ,
38+ ( value , _ ) => {
39+ upsert ( {
3140 groupId,
3241 uid,
3342 componentName,
3443 componentInstance : instance ,
3544 debugState : value ,
3645 } )
37- } )
38- } ,
39- { deep : true } ,
40- )
41-
46+ } ,
47+ {
48+ immediate : true ,
49+ deep : true ,
50+ } ,
51+ )
52+ } )
4253 return state
4354}
Original file line number Diff line number Diff line change @@ -8,7 +8,8 @@ import type {
88 VuebuggerEntry ,
99} from './types'
1010
11- const INSPECTOR_ID = 'composables'
11+ const INSPECTOR_ID = 'vuebugger-inspector'
12+ const TIMELINE_ID = 'vuebugger-timeline'
1213
1314export const handleGetInspectorTree : DevtoolsApiHandler <
1415 'getInspectorTree'
@@ -123,16 +124,26 @@ export function setupComposableDevtools<T>(app: App<T>) {
123124 treeFilterPlaceholder :
124125 'Search by composable or component name...' ,
125126 } )
127+ api . addTimelineLayer ( {
128+ id : TIMELINE_ID ,
129+ label : 'Vuebugger' ,
130+ color : 155 ,
131+ } )
126132
127- onUpdate (
128- (
129- componentInstance : VuebuggerEntry [ 'componentInstance' ] ,
130- ) => {
131- api . sendInspectorTree ( INSPECTOR_ID )
132- api . sendInspectorState ( INSPECTOR_ID )
133- api . notifyComponentUpdate ( componentInstance )
134- } ,
135- )
133+ onUpdate ( ( entry : VuebuggerEntry ) => {
134+ api . sendInspectorTree ( INSPECTOR_ID )
135+ api . sendInspectorState ( INSPECTOR_ID )
136+ api . notifyComponentUpdate ( entry . componentInstance )
137+ api . addTimelineEvent ( {
138+ layerId : TIMELINE_ID ,
139+ event : {
140+ time : api . now ( ) ,
141+ data : entry ,
142+ title : `${ entry . uid } state change` ,
143+ groupId : entry . uid ,
144+ } ,
145+ } )
146+ } )
136147
137148 api . on . getInspectorTree ( handleGetInspectorTree )
138149 api . on . getInspectorState ( handleGetInspectorState ( api ) )
Original file line number Diff line number Diff line change @@ -10,17 +10,14 @@ export const byGroupId = new Map<
1010 Set < VuebuggerEntry [ 'uid' ] >
1111> ( )
1212
13- const callbacks : ( (
14- componentInstance : VuebuggerEntry [ 'componentInstance' ] ,
15- ) => void ) [ ] = [ ]
16- const runCallbacks = (
17- componentInstance : VuebuggerEntry [ 'componentInstance' ] ,
18- ) => callbacks . forEach ( ( cb ) => cb ( componentInstance ) )
13+ const callbacks : ( ( entry : VuebuggerEntry ) => void ) [ ] = [ ]
14+ const runCallbacks = ( entry : VuebuggerEntry ) =>
15+ callbacks . forEach ( ( cb ) => cb ( entry ) )
1916const withCallbacks =
2017 ( fn : ( entry : VuebuggerEntry ) => void ) =>
2118 ( entry : VuebuggerEntry ) => {
2219 fn ( entry )
23- runCallbacks ( entry . componentInstance )
20+ runCallbacks ( entry )
2421 }
2522
2623export const upsert = withCallbacks (
@@ -44,9 +41,7 @@ export const remove = withCallbacks(
4441)
4542
4643export const onUpdate = (
47- fn : (
48- componentInstance : VuebuggerEntry [ 'componentInstance' ] ,
49- ) => void ,
44+ fn : ( entry : VuebuggerEntry ) => void ,
5045) => {
5146 callbacks . push ( fn )
5247}
You can’t perform that action at this time.
0 commit comments