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+ getCurrentInstance ,
3+ getCurrentScope ,
4+ onBeforeUnmount ,
5+ watch ,
6+ } from 'vue'
27import { remove , upsert } from './registry'
38import type { VuebuggerEntry } from './types'
49
@@ -16,28 +21,33 @@ export function debug<T extends Record<string, any>>(
1621 'No component'
1722 const uid = `${ componentName } /${ groupId } -${ Math . random ( ) . toString ( 36 ) . slice ( 2 , 9 ) } `
1823
19- watch (
20- ( ) => state ,
21- ( value , _ , onCleanup ) => {
22- upsert ( {
24+ const scope = getCurrentScope ( )
25+ scope ?. run ( ( ) => {
26+ onBeforeUnmount ( ( ) =>
27+ remove ( {
2328 groupId,
2429 uid,
2530 componentName,
2631 componentInstance : instance ,
27- debugState : value ,
28- } )
29- onCleanup ( ( ) => {
30- remove ( {
32+ debugState : state ,
33+ } ) ,
34+ )
35+ watch (
36+ ( ) => state ,
37+ ( value , _ ) => {
38+ upsert ( {
3139 groupId,
3240 uid,
3341 componentName,
3442 componentInstance : instance ,
3543 debugState : value ,
3644 } )
37- } )
38- } ,
39- { deep : true } ,
40- )
41-
45+ } ,
46+ {
47+ immediate : true ,
48+ deep : true ,
49+ } ,
50+ )
51+ } )
4252 return state
4353}
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,27 @@ 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+ meta : { vin : 'was here' } ,
145+ } ,
146+ } )
147+ } )
136148
137149 api . on . getInspectorTree ( handleGetInspectorTree )
138150 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