File tree 2 files changed +15
-1
lines changed
2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,20 @@ describe('reactivity/computed', () => {
33
33
expect ( cValue . value ) . toBe ( 1 )
34
34
} )
35
35
36
+ it ( 'pass oldValue to computed getter' , ( ) => {
37
+ const count = ref ( 0 )
38
+ const oldValue = ref ( )
39
+ const curValue = computed ( pre => {
40
+ oldValue . value = pre
41
+ return count . value
42
+ } )
43
+ expect ( curValue . value ) . toBe ( 0 )
44
+ expect ( oldValue . value ) . toBe ( undefined )
45
+ count . value ++
46
+ expect ( curValue . value ) . toBe ( 1 )
47
+ expect ( oldValue . value ) . toBe ( 0 )
48
+ } )
49
+
36
50
it ( 'should compute lazily' , ( ) => {
37
51
const value = reactive < { foo ?: number } > ( { } )
38
52
const getter = vi . fn ( ( ) => value . foo )
Original file line number Diff line number Diff line change @@ -381,7 +381,7 @@ export function refreshComputed(computed: ComputedRefImpl): false | undefined {
381
381
382
382
try {
383
383
prepareDeps ( computed )
384
- const value = computed . fn ( )
384
+ const value = computed . fn ( computed . _value )
385
385
if ( dep . version === 0 || hasChanged ( value , computed . _value ) ) {
386
386
computed . _value = value
387
387
dep . version ++
You can’t perform that action at this time.
0 commit comments