File tree Expand file tree Collapse file tree 2 files changed +24
-8
lines changed
Expand file tree Collapse file tree 2 files changed +24
-8
lines changed Original file line number Diff line number Diff line change @@ -1017,6 +1017,17 @@ describe('reactivity/computed', () => {
10171017 expect ( cValue . value ) . toBe ( 1 )
10181018 } )
10191019
1020+ test ( 'should not recompute if computed does not track reactive data' , async ( ) => {
1021+ const spy = vi . fn ( )
1022+ const c1 = computed ( ( ) => spy ( ) )
1023+
1024+ c1 . value
1025+ ref ( 0 ) . value ++ // update globalVersion
1026+ c1 . value
1027+
1028+ expect ( spy ) . toBeCalledTimes ( 1 )
1029+ } )
1030+
10201031 test ( 'computed should remain live after losing all subscribers' , ( ) => {
10211032 const state = reactive ( { a : 1 } )
10221033 const p = computed ( ( ) => state . a + 1 )
Original file line number Diff line number Diff line change @@ -46,9 +46,14 @@ export enum EffectFlags {
4646 /**
4747 * ReactiveEffect only
4848 */
49- ALLOW_RECURSE = 1 << 7 ,
50- PAUSED = 1 << 8 ,
51- NOTIFIED = 1 << 9 ,
49+ ACTIVE = 1 << 0 ,
50+ RUNNING = 1 << 1 ,
51+ TRACKING = 1 << 2 ,
52+ NOTIFIED = 1 << 3 ,
53+ DIRTY = 1 << 4 ,
54+ ALLOW_RECURSE = 1 << 5 ,
55+ PAUSED = 1 << 6 ,
56+ EVALUATED = 1 << 7 ,
5257 STOP = 1 << 10 ,
5358}
5459
@@ -160,6 +165,11 @@ export class ReactiveEffect<T = any> implements ReactiveEffectOptions {
160165 ) {
161166 return true
162167 }
168+ // @ts -expect-error only for backwards compatibility where libs manually set
169+ // this flag - e.g. Pinia's testing module
170+ if ( ( this as any ) . _dirty ) {
171+ return true
172+ }
163173 return false
164174 }
165175}
@@ -168,11 +178,6 @@ if (__DEV__) {
168178 setupOnTrigger ( ReactiveEffect )
169179}
170180
171- export interface ReactiveEffectRunner < T = any > {
172- ( ) : T
173- effect : ReactiveEffect
174- }
175-
176181export function effect < T = any > (
177182 fn : ( ) => T ,
178183 options ?: ReactiveEffectOptions ,
You can’t perform that action at this time.
0 commit comments