Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/reactivity/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ export enum EffectFlags {
* @internal
*/
INHERITED_PAUSED = 1 << 11,
PAUSED = EffectFlags.SELF_PAUSED | EffectFlags.INHERITED_PAUSED,
/**
* paused by the runtime apart from `pause()`, e.g. KeepAlive deactivating a
* component
* @internal
*/
RUNTIME_PAUSED = 1 << 12,
PAUSED = EffectFlags.SELF_PAUSED |
EffectFlags.INHERITED_PAUSED |
EffectFlags.RUNTIME_PAUSED,
}

export class ReactiveEffect<T = any>
Expand Down Expand Up @@ -194,6 +202,12 @@ if (__DEV__) {
setupOnTrigger(ReactiveEffect)
}

// Makes the next notification of an effect run it, for an update its
// dependencies do not track.
export function markEffectDirty(effect: ReactiveEffect): void {
effect.flags |= ReactiveFlags.Dirty
}

export function effect<T = any>(
fn: () => T,
options?: ReactiveEffectOptions,
Expand Down
8 changes: 4 additions & 4 deletions packages/reactivity/src/effectScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class EffectScope implements ReactiveNode {
}
}

function pauseScope(scope: EffectScope, by: EffectFlags): void {
export function pauseScope(scope: EffectScope, by: EffectFlags): void {
const wasPaused = scope.flags & EffectFlags.PAUSED
scope.flags |= by
if (wasPaused) return
Expand All @@ -180,9 +180,9 @@ function pauseScope(scope: EffectScope, by: EffectFlags): void {
}
}

// Lifts one of the two pauses; the subtree resumes once neither is left. An
// effect run on the way may pause or stop any part of the subtree again.
function resumeScope(scope: EffectScope, by: EffectFlags): void {
// Lifts one of its pauses; the subtree resumes once none is left. An effect run
// on the way may pause or stop any part of the subtree again.
export function resumeScope(scope: EffectScope, by: EffectFlags): void {
if ((scope.flags &= ~by) & EffectFlags.PAUSED) return
let link = scope.deps
while (link !== undefined) {
Expand Down
12 changes: 12 additions & 0 deletions packages/reactivity/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export {
onEffectCleanup,
ReactiveEffect,
EffectFlags,
/**
* @internal
*/
markEffectDirty,
type ReactiveEffectRunner,
type ReactiveEffectOptions,
type EffectScheduler,
Expand Down Expand Up @@ -85,6 +89,14 @@ export {
*/
setCurrentScope,
onScopeDispose,
/**
* @internal
*/
pauseScope,
/**
* @internal
*/
resumeScope,
} from './effectScope'
export { reactiveReadArray, shallowReadArray } from './arrayInstrumentations'
export { TrackOpTypes, TriggerOpTypes, ReactiveFlags } from './constants'
Expand Down
Loading
Loading