File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
packages/shared/computedWithControl Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,23 @@ describe('computedWithControl', () => {
2525 expect ( computed . value ) . toBe ( 'BAR' )
2626 } )
2727
28+ it . runIf ( isVue3 ) ( 'optional old value' , ( ) => {
29+ const trigger = ref ( 0 )
30+
31+ const computed = computedWithControl ( trigger , ( oldValue ?: number ) =>
32+ oldValue ? oldValue * 2 : 1 )
33+
34+ expect ( computed . value ) . toBe ( 1 )
35+
36+ trigger . value += 1
37+
38+ expect ( computed . value ) . toBe ( 2 )
39+
40+ trigger . value -= 1
41+
42+ expect ( computed . value ) . toBe ( 4 )
43+ } )
44+
2845 it . runIf ( isVue3 ) ( 'custom trigger' , ( ) => {
2946 let count = 0
3047 const computed = computedWithControl ( ( ) => { } , ( ) => count )
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ export function computedWithControl<T, S>(
5454 return {
5555 get ( ) {
5656 if ( dirty . value ) {
57- v = get ( )
57+ v = get ( v )
5858 dirty . value = false
5959 }
6060 track ( )
You can’t perform that action at this time.
0 commit comments