Skip to content

Commit 033b2be

Browse files
committed
perf: throttle component update hook
1 parent dd47083 commit 033b2be

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

packages/app-backend-core/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
SharedData,
2121
} from '@vue-devtools/shared-utils'
2222
import debounce from 'lodash/debounce'
23+
import throttle from 'lodash/throttle'
2324
import { hook } from './global-hook'
2425
import { subscribe, unsubscribe, isSubscribed } from './util/subscriptions'
2526
import { highlight, unHighlight } from './highlighter'
@@ -110,7 +111,7 @@ async function connect () {
110111

111112
// Components
112113

113-
hook.on(HookEvents.COMPONENT_UPDATED, async (app, uid, parentUid, component) => {
114+
hook.on(HookEvents.COMPONENT_UPDATED, throttle(async (app, uid, parentUid, component) => {
114115
try {
115116
let id: string
116117
let appRecord: AppRecord
@@ -136,7 +137,7 @@ async function connect () {
136137
console.error(e)
137138
}
138139
}
139-
})
140+
}, 1000 / 10))
140141

141142
hook.on(HookEvents.COMPONENT_ADDED, async (app, uid, parentUid, component) => {
142143
try {

packages/shell-dev-vue3/src/App.vue

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export default {
6060
return {
6161
count: 0,
6262
text: 'Meow',
63+
time: 0,
6364
}
6465
},
6566
@@ -69,6 +70,17 @@ export default {
6970
app.use(SimplePlugin)
7071
app.mount('#nested-app')
7172
},
73+
74+
startTimer () {
75+
this.stopTimer()
76+
this.timer = setInterval(() => {
77+
this.time++
78+
}, 1)
79+
},
80+
81+
stopTimer () {
82+
clearInterval(this.timer)
83+
},
7284
},
7385
}
7486
</script>
@@ -84,6 +96,16 @@ export default {
8496
<span>{{ text }}</span>
8597
</div>
8698

99+
<div>
100+
<button @click="startTimer">
101+
Start timer
102+
</button>
103+
<button @click="stopTimer">
104+
Stop timer
105+
</button>
106+
<span>{{ time }}</span>
107+
</div>
108+
87109
<div>
88110
<Heavy
89111
v-for="i in count"

0 commit comments

Comments
 (0)