Skip to content

Commit 715aedc

Browse files
committed
feat(KeepAlive): pause deactivated components
1 parent ff5abf0 commit 715aedc

20 files changed

Lines changed: 2280 additions & 71 deletions

File tree

‎packages/reactivity/src/effect.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ export enum EffectFlags {
6161
* @internal
6262
*/
6363
INHERITED_PAUSED = 1 << 11,
64-
PAUSED = EffectFlags.SELF_PAUSED | EffectFlags.INHERITED_PAUSED,
64+
/**
65+
* paused by the runtime apart from `pause()`, e.g. KeepAlive deactivating a
66+
* component
67+
* @internal
68+
*/
69+
RUNTIME_PAUSED = 1 << 12,
70+
PAUSED = EffectFlags.SELF_PAUSED |
71+
EffectFlags.INHERITED_PAUSED |
72+
EffectFlags.RUNTIME_PAUSED,
6573
}
6674

6775
export class ReactiveEffect<T = any>
@@ -194,6 +202,12 @@ if (__DEV__) {
194202
setupOnTrigger(ReactiveEffect)
195203
}
196204

205+
// Makes the next notification of an effect run it, for an update its
206+
// dependencies do not track.
207+
export function markEffectDirty(effect: ReactiveEffect): void {
208+
effect.flags |= ReactiveFlags.Dirty
209+
}
210+
197211
export function effect<T = any>(
198212
fn: () => T,
199213
options?: ReactiveEffectOptions,

‎packages/reactivity/src/effectScope.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class EffectScope implements ReactiveNode {
156156
}
157157
}
158158

159-
function pauseScope(scope: EffectScope, by: EffectFlags): void {
159+
export function pauseScope(scope: EffectScope, by: EffectFlags): void {
160160
const wasPaused = scope.flags & EffectFlags.PAUSED
161161
scope.flags |= by
162162
if (wasPaused) return
@@ -180,9 +180,9 @@ function pauseScope(scope: EffectScope, by: EffectFlags): void {
180180
}
181181
}
182182

183-
// Lifts one of the two pauses; the subtree resumes once neither is left. An
184-
// effect run on the way may pause or stop any part of the subtree again.
185-
function resumeScope(scope: EffectScope, by: EffectFlags): void {
183+
// Lifts one of its pauses; the subtree resumes once none is left. An effect run
184+
// on the way may pause or stop any part of the subtree again.
185+
export function resumeScope(scope: EffectScope, by: EffectFlags): void {
186186
if ((scope.flags &= ~by) & EffectFlags.PAUSED) return
187187
let link = scope.deps
188188
while (link !== undefined) {

‎packages/reactivity/src/index.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ export {
5858
onEffectCleanup,
5959
ReactiveEffect,
6060
EffectFlags,
61+
/**
62+
* @internal
63+
*/
64+
markEffectDirty,
6165
type ReactiveEffectRunner,
6266
type ReactiveEffectOptions,
6367
type EffectScheduler,
@@ -85,6 +89,14 @@ export {
8589
*/
8690
setCurrentScope,
8791
onScopeDispose,
92+
/**
93+
* @internal
94+
*/
95+
pauseScope,
96+
/**
97+
* @internal
98+
*/
99+
resumeScope,
88100
} from './effectScope'
89101
export { reactiveReadArray, shallowReadArray } from './arrayInstrumentations'
90102
export { TrackOpTypes, TriggerOpTypes, ReactiveFlags } from './constants'

0 commit comments

Comments
 (0)