Skip to content

Commit 8677132

Browse files
committed
refactor: defer mixin to composable
1 parent 0c70181 commit 8677132

File tree

4 files changed

+39
-44
lines changed

4 files changed

+39
-44
lines changed

packages/app-frontend/src/features/inspector/StateInspector.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import StateType from './StateType.vue'
33
44
import Vue from 'vue'
5-
import Defer from '@front/mixins/defer'
5+
import { useDefer } from '@front/util/defer'
66
77
const keyOrder = {
88
props: 1,
@@ -30,10 +30,6 @@ export default {
3030
StateType,
3131
},
3232
33-
mixins: [
34-
Defer(),
35-
],
36-
3733
props: {
3834
state: {
3935
type: Object,
@@ -46,6 +42,14 @@ export default {
4642
},
4743
},
4844
45+
setup () {
46+
const { defer } = useDefer()
47+
48+
return {
49+
defer,
50+
}
51+
},
52+
4953
data () {
5054
return {
5155
expandedState: {},

packages/app-frontend/src/features/timeline/TimelineEventList.vue

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import TimelineEventListItem from './TimelineEventListItem.vue'
44
55
import { computed, ref, watch, defineComponent } from '@vue/composition-api'
66
import { getStorage, setStorage } from '@vue-devtools/shared-utils'
7-
import Defer from '@front/mixins/defer'
87
import { useRoute, useRouter } from '@front/util/router'
98
import { onKeyDown } from '@front/util/keyboard'
109
import { useInspectedEvent, useSelectedEvent, selectEvent, useLayers } from './composable'
@@ -19,10 +18,6 @@ export default defineComponent({
1918
EmptyPane,
2019
},
2120
22-
mixins: [
23-
Defer(),
24-
],
25-
2621
setup () {
2722
const route = useRoute()
2823
const router = useRouter()

packages/app-frontend/src/mixins/defer.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { ref, onMounted } from '@vue/composition-api'
2+
3+
export function useDefer (count = 10) {
4+
const displayPriority = ref(0)
5+
6+
function step () {
7+
requestAnimationFrame(() => {
8+
displayPriority.value++
9+
if (displayPriority.value < count) {
10+
step()
11+
}
12+
})
13+
}
14+
15+
function runDisplayPriority () {
16+
step()
17+
}
18+
19+
function defer (priority) {
20+
return displayPriority.value >= priority
21+
}
22+
23+
onMounted(() => {
24+
runDisplayPriority()
25+
})
26+
27+
return {
28+
defer,
29+
}
30+
}

0 commit comments

Comments
 (0)