Skip to content

Commit

Permalink
perf(reactive-vue): optimize vue3 tracker performance consumption of …
Browse files Browse the repository at this point in the history
…multiple instances (#2911)

* fix(reactive-vue): fix vue3 render dependency collection broken

* perf(reactive-vue): optimize vue3 tracker performance consumption of multiple instances
  • Loading branch information
ethesky-rcplatformhk authored Mar 9, 2022
1 parent f434836 commit 83e6a35
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
4 changes: 1 addition & 3 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"version": "2.0.14",
"npmClient": "yarn",
"useWorkspaces": true,
"npmClientArgs": [
"--ignore-engines"
],
"npmClientArgs": ["--ignore-engines"],
"command": {
"version": {
"forcePublish": true,
Expand Down
16 changes: 8 additions & 8 deletions packages/reactive-vue/src/hooks/useObserver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Tracker } from '@formily/reactive'
import { getCurrentInstance, onBeforeUnmount, isVue3 } from 'vue-demi'
import { getCurrentInstance, onBeforeUnmount, isVue3, nextTick } from 'vue-demi'
import { IObserverOptions } from '../types'

/* istanbul ignore next */
Expand All @@ -23,8 +23,8 @@ export const useObserver = (options?: IObserverOptions) => {
},
set(newValue) {
vm['_updateEffectRun'] = newValue.run
disposeTracker()
const newTracker = () => {
disposeTracker()
tracker = new Tracker(() => {
if (options?.scheduler && typeof options.scheduler === 'function') {
options.scheduler(update)
Expand All @@ -33,15 +33,15 @@ export const useObserver = (options?: IObserverOptions) => {
}
})
}
const update = function () {
newTracker()
let refn: any = null
let runUpdate = () => {
tracker?.track(() => {
refn = vm['_updateEffectRun'].call(newValue)
vm['_updateEffectRun'].call(newValue)
})
return refn
}

const update = function () {
nextTick(runUpdate)
}
newTracker()
newValue.run = update
vm['_updateEffect'] = newValue
},
Expand Down

0 comments on commit 83e6a35

Please sign in to comment.