File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed
packages/shared/reactiveComputed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -53,4 +53,28 @@ describe('reactiveComputed', () => {
53
53
expect ( dummy ) . toBe ( 1 )
54
54
expect ( type ) . toBe ( 'foo' )
55
55
} )
56
+
57
+ it ( 'should allow for previous value access (for vue 3.4+)' , ( ) => {
58
+ const test = ref ( 0 )
59
+
60
+ const obj = reactiveComputed < { test : number , num : number } > (
61
+ prev => ( { test : test . value , num : ( prev ?. num ?? 2 ) } ) ,
62
+ )
63
+
64
+ obj . num = 5
65
+ expect ( obj ) . toMatchInlineSnapshot ( `
66
+ {
67
+ "num": 5,
68
+ "test": 0,
69
+ }
70
+ ` )
71
+
72
+ test . value = 1
73
+ expect ( obj ) . toMatchInlineSnapshot ( `
74
+ {
75
+ "num": 5,
76
+ "test": 1,
77
+ }
78
+ ` )
79
+ } )
56
80
} )
Original file line number Diff line number Diff line change 1
- import type { UnwrapNestedRefs } from 'vue'
1
+ import type { ComputedGetter , UnwrapNestedRefs } from 'vue'
2
2
import { computed } from 'vue'
3
3
import { toReactive } from '../toReactive'
4
4
5
5
/**
6
6
* Computed reactive object.
7
7
*/
8
- export function reactiveComputed < T extends object > ( fn : ( ) => T ) : UnwrapNestedRefs < T > {
8
+ export function reactiveComputed < T extends object > ( fn : ComputedGetter < T > ) : UnwrapNestedRefs < T > {
9
9
return toReactive ( computed ( fn ) )
10
10
}
You can’t perform that action at this time.
0 commit comments