Skip to content

Commit

Permalink
refactor: use NOOP for empty triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Oct 26, 2023
1 parent b98b6b8 commit 600966b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
14 changes: 5 additions & 9 deletions packages/reactivity/src/effect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extend, getGlobalThis } from '@vue/shared'
import { NOOP, extend, getGlobalThis } from '@vue/shared'
import type { ComputedRefImpl } from './computed'
import { DirtyLevels, TrackOpTypes, TriggerOpTypes } from './constants'
import type { Dep } from './dep'
Expand Down Expand Up @@ -237,15 +237,11 @@ export function effect<T = any>(
fn = (fn as ReactiveEffectRunner).effect.fn
}

const _effect = new ReactiveEffect(
fn,
() => {},
() => {
if (_effect.dirty) {
_effect.run()
}
const _effect = new ReactiveEffect(fn, NOOP, () => {
if (_effect.dirty) {
_effect.run()
}
)
})
if (options) {
extend(_effect, options)
if (options.scope) recordEffectScope(_effect, options.scope)
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/apiWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ function doWatch(
scheduler = () => queueJob(job)
}

const effect = new ReactiveEffect(getter, () => {}, scheduler)
const effect = new ReactiveEffect(getter, NOOP, scheduler)

if (__DEV__) {
effect.onTrack = onTrack
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ function baseCreateRenderer(
// create reactive effect for rendering
const effect = (instance.effect = new ReactiveEffect(
componentUpdateFn,
() => {},
NOOP,
() => queueJob(update),
instance.scope // track it in component's effect scope
))
Expand Down

0 comments on commit 600966b

Please sign in to comment.