@@ -10,6 +10,7 @@ import { findRelatedComponent } from './utils'
10
10
import { stringify , classify , camelize , set , has , parse , getComponentName , getCustomRefDetails } from '../util'
11
11
import ComponentSelector from './component-selector'
12
12
import SharedData , { init as initSharedData } from 'src/shared-data'
13
+ import { init as initStorage } from 'src/storage'
13
14
import { isBrowser , target } from 'src/devtools/env'
14
15
15
16
// hook should have been injected before this executes.
@@ -47,130 +48,132 @@ export function initBackend (_bridge) {
47
48
}
48
49
49
50
function connect ( Vue ) {
50
- initSharedData ( {
51
- bridge,
52
- Vue
53
- } )
51
+ initStorage ( ) . then ( ( ) => {
52
+ initSharedData ( {
53
+ bridge,
54
+ Vue
55
+ } )
54
56
55
- hook . currentTab = 'components'
56
- bridge . on ( 'switch-tab' , tab => {
57
- hook . currentTab = tab
58
- if ( tab === 'components' ) {
59
- flush ( )
60
- }
61
- } )
57
+ hook . currentTab = 'components'
58
+ bridge . on ( 'switch-tab' , tab => {
59
+ hook . currentTab = tab
60
+ if ( tab === 'components' ) {
61
+ flush ( )
62
+ }
63
+ } )
62
64
63
- // the backend may get injected to the same page multiple times
64
- // if the user closes and reopens the devtools.
65
- // make sure there's only one flush listener.
66
- hook . off ( 'flush' )
67
- hook . on ( 'flush' , ( ) => {
68
- if ( hook . currentTab === 'components' ) {
69
- flush ( )
70
- }
71
- } )
65
+ // the backend may get injected to the same page multiple times
66
+ // if the user closes and reopens the devtools.
67
+ // make sure there's only one flush listener.
68
+ hook . off ( 'flush' )
69
+ hook . on ( 'flush' , ( ) => {
70
+ if ( hook . currentTab === 'components' ) {
71
+ flush ( )
72
+ }
73
+ } )
72
74
73
- bridge . on ( 'select-instance' , id => {
74
- currentInspectedId = id
75
- const instance = findInstanceOrVnode ( id )
76
- if ( ! instance ) return
77
- if ( ! / : f u n c t i o n a l : / . test ( id ) ) bindToConsole ( instance )
78
- flush ( )
79
- bridge . send ( 'instance-selected' )
80
- } )
75
+ bridge . on ( 'select-instance' , id => {
76
+ currentInspectedId = id
77
+ const instance = findInstanceOrVnode ( id )
78
+ if ( ! instance ) return
79
+ if ( ! / : f u n c t i o n a l : / . test ( id ) ) bindToConsole ( instance )
80
+ flush ( )
81
+ bridge . send ( 'instance-selected' )
82
+ } )
81
83
82
- bridge . on ( 'scroll-to-instance' , id => {
83
- const instance = findInstanceOrVnode ( id )
84
- if ( instance ) {
85
- scrollIntoView ( instance )
86
- highlight ( instance )
87
- }
88
- } )
84
+ bridge . on ( 'scroll-to-instance' , id => {
85
+ const instance = findInstanceOrVnode ( id )
86
+ if ( instance ) {
87
+ scrollIntoView ( instance )
88
+ highlight ( instance )
89
+ }
90
+ } )
89
91
90
- bridge . on ( 'filter-instances' , _filter => {
91
- filter = _filter . toLowerCase ( )
92
- flush ( )
93
- } )
92
+ bridge . on ( 'filter-instances' , _filter => {
93
+ filter = _filter . toLowerCase ( )
94
+ flush ( )
95
+ } )
94
96
95
- bridge . on ( 'refresh' , scan )
97
+ bridge . on ( 'refresh' , scan )
96
98
97
- bridge . on ( 'enter-instance' , id => {
98
- const instance = findInstanceOrVnode ( id )
99
- if ( instance ) highlight ( instance )
100
- } )
99
+ bridge . on ( 'enter-instance' , id => {
100
+ const instance = findInstanceOrVnode ( id )
101
+ if ( instance ) highlight ( instance )
102
+ } )
101
103
102
- bridge . on ( 'leave-instance' , unHighlight )
104
+ bridge . on ( 'leave-instance' , unHighlight )
103
105
104
- // eslint-disable-next-line no-new
105
- new ComponentSelector ( bridge , instanceMap )
106
+ // eslint-disable-next-line no-new
107
+ new ComponentSelector ( bridge , instanceMap )
106
108
107
- // Get the instance id that is targeted by context menu
108
- bridge . on ( 'get-context-menu-target' , ( ) => {
109
- const instance = target . __VUE_DEVTOOLS_CONTEXT_MENU_TARGET__
109
+ // Get the instance id that is targeted by context menu
110
+ bridge . on ( 'get-context-menu-target' , ( ) => {
111
+ const instance = target . __VUE_DEVTOOLS_CONTEXT_MENU_TARGET__
110
112
111
- target . __VUE_DEVTOOLS_CONTEXT_MENU_TARGET__ = null
112
- target . __VUE_DEVTOOLS_CONTEXT_MENU_HAS_TARGET__ = false
113
+ target . __VUE_DEVTOOLS_CONTEXT_MENU_TARGET__ = null
114
+ target . __VUE_DEVTOOLS_CONTEXT_MENU_HAS_TARGET__ = false
113
115
114
- if ( instance ) {
115
- const id = instance . __VUE_DEVTOOLS_UID__
116
- if ( id ) {
117
- return bridge . send ( 'inspect-instance' , id )
116
+ if ( instance ) {
117
+ const id = instance . __VUE_DEVTOOLS_UID__
118
+ if ( id ) {
119
+ return bridge . send ( 'inspect-instance' , id )
120
+ }
118
121
}
119
- }
120
-
121
- toast ( 'No Vue component was found' , 'warn' )
122
- } )
123
122
124
- bridge . on ( 'set-instance-data' , args => {
125
- setStateValue ( args )
126
- flush ( )
127
- } )
123
+ toast ( 'No Vue component was found' , 'warn' )
124
+ } )
128
125
129
- // vuex
130
- if ( hook . store ) {
131
- initVuexBackend ( hook , bridge , hook . store . commit === undefined )
132
- } else {
133
- hook . once ( 'vuex:init' , store => {
134
- initVuexBackend ( hook , bridge , store . commit === undefined )
126
+ bridge . on ( 'set-instance-data' , args => {
127
+ setStateValue ( args )
128
+ flush ( )
135
129
} )
136
- }
137
130
138
- hook . once ( 'router:init' , ( ) => {
139
- initRouterBackend ( hook . Vue , bridge , rootInstances )
140
- } )
131
+ // vuex
132
+ if ( hook . store ) {
133
+ initVuexBackend ( hook , bridge , hook . store . commit === undefined )
134
+ } else {
135
+ hook . once ( 'vuex:init' , store => {
136
+ initVuexBackend ( hook , bridge , store . commit === undefined )
137
+ } )
138
+ }
141
139
142
- // events
143
- initEventsBackend ( Vue , bridge )
140
+ hook . once ( 'router:init' , ( ) => {
141
+ initRouterBackend ( hook . Vue , bridge , rootInstances )
142
+ } )
143
+
144
+ // events
145
+ initEventsBackend ( Vue , bridge )
144
146
145
- target . __VUE_DEVTOOLS_INSPECT__ = inspectInstance
147
+ target . __VUE_DEVTOOLS_INSPECT__ = inspectInstance
146
148
147
- // User project devtools config
148
- if ( target . hasOwnProperty ( 'VUE_DEVTOOLS_CONFIG' ) ) {
149
- const config = target . VUE_DEVTOOLS_CONFIG
149
+ // User project devtools config
150
+ if ( target . hasOwnProperty ( 'VUE_DEVTOOLS_CONFIG' ) ) {
151
+ const config = target . VUE_DEVTOOLS_CONFIG
150
152
151
- // Open in editor
152
- if ( config . hasOwnProperty ( 'openInEditorHost' ) ) {
153
- SharedData . openInEditorHost = config . openInEditorHost
153
+ // Open in editor
154
+ if ( config . hasOwnProperty ( 'openInEditorHost' ) ) {
155
+ SharedData . openInEditorHost = config . openInEditorHost
156
+ }
154
157
}
155
- }
156
158
157
- bridge . log ( 'backend ready.' )
158
- bridge . send ( 'ready' , Vue . version )
159
- bridge . on ( 'log-detected-vue' , ( ) => {
160
- console . log (
161
- `%c vue-devtools %c Detected Vue v${ Vue . version } %c` ,
162
- 'background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff' ,
163
- 'background:#41b883 ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff' ,
164
- 'background:transparent'
165
- )
166
- } )
159
+ bridge . log ( 'backend ready.' )
160
+ bridge . send ( 'ready' , Vue . version )
161
+ bridge . on ( 'log-detected-vue' , ( ) => {
162
+ console . log (
163
+ `%c vue-devtools %c Detected Vue v${ Vue . version } %c` ,
164
+ 'background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff' ,
165
+ 'background:#41b883 ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff' ,
166
+ 'background:transparent'
167
+ )
168
+ } )
167
169
168
- setTimeout ( ( ) => {
169
- scan ( )
170
+ setTimeout ( ( ) => {
171
+ scan ( )
170
172
171
- // perf
172
- initPerfBackend ( Vue , bridge , instanceMap )
173
- } , 0 )
173
+ // perf
174
+ initPerfBackend ( Vue , bridge , instanceMap )
175
+ } , 0 )
176
+ } )
174
177
}
175
178
176
179
export function findInstanceOrVnode ( id ) {
0 commit comments