1
+ import { DevToolsHooks } from '@vite-plugin-vue-devtools/core'
1
2
import { updatePinia } from './pinia'
2
3
import { instance , updateApp , app as vueApp } from './app'
3
4
import { useDevToolsClient } from './client'
4
5
5
- enum DevtoolsHooks {
6
- APP_INIT = 'app:init' ,
7
- COMPONENT_UPDATED = 'component:updated' ,
8
- COMPONENT_ADDED = 'component:added' ,
9
- COMPONENT_REMOVED = 'component:removed' ,
10
- COMPONENT_EMIT = 'component:emit' ,
11
- }
12
-
13
6
function hideInDevtools ( component ) {
14
7
return component ?. root ?. type ?. devtools ?. hide
15
8
}
16
9
17
10
const client = useDevToolsClient ( )
18
11
19
- function produceHook ( ) {
12
+ function subscribeHook ( ) {
20
13
const client = useDevToolsClient ( )
21
14
const hook = client . value . hook
22
- hook . on ( DevtoolsHooks . APP_INIT , ( app ) => {
15
+ hook . on ( DevToolsHooks . APP_INIT , ( app ) => {
23
16
if ( app ?. _vueDevtools_hidden_ )
24
17
return
25
18
vueApp . value = app
@@ -30,7 +23,7 @@ function produceHook() {
30
23
return ( ! app || ( typeof uid !== 'number' && ! uid ) || ! component || hideInDevtools ( component ) )
31
24
}
32
25
33
- hook . on ( DevtoolsHooks . COMPONENT_UPDATED , ( app , uid , parentUid , component ) => {
26
+ hook . on ( DevToolsHooks . COMPONENT_UPDATED , ( app , uid , parentUid , component ) => {
34
27
updatePinia ( component )
35
28
36
29
if ( skipCollect ( app , uid , component ) )
@@ -39,7 +32,7 @@ function produceHook() {
39
32
updateApp ( app , component )
40
33
} )
41
34
42
- hook . on ( DevtoolsHooks . COMPONENT_ADDED , ( app , uid , parentUid , component ) => {
35
+ hook . on ( DevToolsHooks . COMPONENT_ADDED , ( app , uid , parentUid , component ) => {
43
36
updatePinia ( component )
44
37
45
38
if ( skipCollect ( app , uid , component ) )
@@ -49,7 +42,7 @@ function produceHook() {
49
42
updateApp ( app , component )
50
43
} )
51
44
52
- hook . on ( DevtoolsHooks . COMPONENT_REMOVED , ( app , uid , parentUid , component ) => {
45
+ hook . on ( DevToolsHooks . COMPONENT_REMOVED , ( app , uid , parentUid , component ) => {
53
46
updatePinia ( component )
54
47
55
48
if ( skipCollect ( app , uid , component ) )
@@ -60,7 +53,7 @@ function produceHook() {
60
53
updateApp ( app , component )
61
54
} )
62
55
63
- hook . on ( DevtoolsHooks . COMPONENT_EMIT , ( app , uid , parentUid , component ) => {
56
+ hook . on ( DevToolsHooks . COMPONENT_EMIT , ( app , uid , parentUid , component ) => {
64
57
updatePinia ( component )
65
58
66
59
if ( skipCollect ( app , uid , component ) )
@@ -72,7 +65,7 @@ function produceHook() {
72
65
} )
73
66
}
74
67
75
- function ConsumeHook ( buffer : [ string , Record < string , any > ] [ ] ) {
68
+ function publishHook ( buffer : [ string , Record < string , any > ] [ ] ) {
76
69
buffer . forEach ( ( [ _ , { app, component } ] ) => {
77
70
updatePinia ( component )
78
71
updateApp ( app , component )
@@ -81,6 +74,6 @@ function ConsumeHook(buffer: [string, Record<string, any>][]) {
81
74
82
75
export const hookApi = {
83
76
hook : client . value . hook ,
84
- produce : produceHook ,
85
- consume : ConsumeHook ,
77
+ subscribe : subscribeHook ,
78
+ publish : publishHook ,
86
79
}
0 commit comments