Skip to content

Commit

Permalink
Remove allowRecurse field
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Nov 28, 2024
1 parent 64e26cc commit 4331b3e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
9 changes: 6 additions & 3 deletions packages/reactivity/src/debug.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { extend } from '@vue/shared'
import type { DebuggerEventExtraInfo, ReactiveEffectOptions } from './effect'
import type { Link, Subscriber } from './system'
import { type Link, type Subscriber, SubscriberFlags } from './system'

export const triggerEventInfos: DebuggerEventExtraInfo[] = []

Expand Down Expand Up @@ -58,8 +58,11 @@ export function setupFlagsHandler(target: Subscriber): void {
return target._flags
},
set(value) {
// @ts-expect-error
if (!(target._flags >> 2) && !!(value >> 2)) {
if (
// @ts-expect-error
!(target._flags >> SubscriberFlags.DirtyFlagsIndex) &&
!!(value >> SubscriberFlags.DirtyFlagsIndex)
) {
onTrigger(this)
}
// @ts-expect-error
Expand Down
13 changes: 9 additions & 4 deletions packages/reactivity/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import {
} from './system'
import { warn } from './warning'

export enum EffectFlags {
ALLOW_RECURSE = 1 << 2,
}

export type EffectScheduler = (...args: any[]) => any

export type DebuggerEvent = {
Expand All @@ -35,7 +39,6 @@ export interface DebuggerOptions {

export interface ReactiveEffectOptions extends DebuggerOptions {
scheduler?: EffectScheduler
allowRecurse?: boolean
onStop?: () => void
}

Expand All @@ -57,10 +60,9 @@ export class ReactiveEffect<T = any> implements IEffect, ReactiveEffectOptions {
// Subscriber
deps: Link | undefined = undefined
depsTail: Link | undefined = undefined
flags: SubscriberFlags = SubscriberFlags.Dirty
flags: number = SubscriberFlags.Dirty

pauseLevel: PauseLevels = PauseLevels.None
allowRecurse = false

/**
* @internal
Expand Down Expand Up @@ -139,7 +141,10 @@ export class ReactiveEffect<T = any> implements IEffect, ReactiveEffectOptions {
}
setActiveSub(prevSub, prevTrackId)
endTrack(this)
if (this.allowRecurse && this.flags & SubscriberFlags.CanPropagate) {
if (
this.flags & SubscriberFlags.CanPropagate &&
this.flags & EffectFlags.ALLOW_RECURSE
) {
this.flags &= ~SubscriberFlags.CanPropagate
this.notify()
}
Expand Down
1 change: 1 addition & 0 deletions packages/reactivity/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export {
resetTracking,
onEffectCleanup,
ReactiveEffect,
EffectFlags,
type ReactiveEffectRunner,
type ReactiveEffectOptions,
type EffectScheduler,
Expand Down
13 changes: 9 additions & 4 deletions packages/reactivity/src/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export enum SubscriberFlags {
ToCheckDirty = 1 << 3,
Dirty = 1 << 4,
Dirtys = SubscriberFlags.ToCheckDirty | SubscriberFlags.Dirty,
All = SubscriberFlags.Tracking |
SubscriberFlags.CanPropagate |
SubscriberFlags.Dirtys,

DirtyFlagsIndex = 3,
}

let batchDepth = 0
Expand Down Expand Up @@ -141,7 +146,7 @@ export function propagate(subs: Link): void {
const subFlags = sub.flags

if (!(subFlags & SubscriberFlags.Tracking)) {
let canPropagate = !(subFlags >> 2)
let canPropagate = !(subFlags >> SubscriberFlags.DirtyFlagsIndex)
if (!canPropagate && subFlags & SubscriberFlags.CanPropagate) {
sub.flags &= ~SubscriberFlags.CanPropagate
canPropagate = true
Expand Down Expand Up @@ -171,7 +176,7 @@ export function propagate(subs: Link): void {
sub.flags |= targetFlag
}
} else if (isValidLink(link, sub)) {
if (!(subFlags >> 2)) {
if (!(subFlags >> SubscriberFlags.DirtyFlagsIndex)) {
sub.flags |= targetFlag | SubscriberFlags.CanPropagate
const subSubs = (sub as Dependency).subs
if (subSubs !== undefined) {
Expand Down Expand Up @@ -293,7 +298,7 @@ export function checkDirty(deps: Link): boolean {

export function startTrack(sub: Subscriber): void {
sub.depsTail = undefined
sub.flags = SubscriberFlags.Tracking
sub.flags = (sub.flags & ~SubscriberFlags.All) | SubscriberFlags.Tracking
}

export function endTrack(sub: Subscriber): void {
Expand Down Expand Up @@ -343,7 +348,7 @@ function clearTrack(link: Link): void {

if (dep.subs === undefined && 'deps' in dep) {
if ('notify' in dep) {
dep.flags = SubscriberFlags.None
dep.flags &= ~SubscriberFlags.Dirtys
} else {
dep.flags |= SubscriberFlags.Dirty
}
Expand Down
11 changes: 8 additions & 3 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ import {
queueJob,
queuePostFlushCb,
} from './scheduler'
import { ReactiveEffect, pauseTracking, resetTracking } from '@vue/reactivity'
import {
EffectFlags,
ReactiveEffect,
pauseTracking,
resetTracking,
} from '@vue/reactivity'
import { updateProps } from './componentProps'
import { updateSlots } from './componentSlots'
import { popWarningContext, pushWarningContext, warn } from './warning'
Expand Down Expand Up @@ -2419,10 +2424,10 @@ function toggleRecurse(
allowed: boolean,
) {
if (allowed) {
effect.allowRecurse = true
effect.flags |= EffectFlags.ALLOW_RECURSE
job.flags! |= SchedulerJobFlags.ALLOW_RECURSE
} else {
effect.allowRecurse = false
effect.flags &= ~EffectFlags.ALLOW_RECURSE
job.flags! &= ~SchedulerJobFlags.ALLOW_RECURSE
}
}
Expand Down

0 comments on commit 4331b3e

Please sign in to comment.