File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 8
8
effect ,
9
9
ref ,
10
10
shallowReadonly ,
11
- isProxy
11
+ isProxy ,
12
+ computed
12
13
} from '../src'
13
14
14
15
/**
@@ -435,6 +436,21 @@ describe('reactivity/readonly', () => {
435
436
) . toHaveBeenWarned ( )
436
437
} )
437
438
439
+ // https://github.com/vuejs/vue-next/issues/3376
440
+ test ( 'calling readonly on computed should allow computed to set its private properties' , ( ) => {
441
+ const r = ref < boolean > ( false )
442
+ const c = computed ( ( ) => r . value )
443
+ const rC = readonly ( c )
444
+
445
+ r . value = true
446
+
447
+ expect ( rC . value ) . toBe ( true )
448
+ ; ( rC as any ) . randomProperty = true
449
+
450
+ expect (
451
+ 'Set operation on key "randomProperty" failed: target is readonly.'
452
+ ) . toHaveBeenWarned ( )
453
+ } )
438
454
describe ( 'shallowReadonly' , ( ) => {
439
455
test ( 'should not make non-reactive properties reactive' , ( ) => {
440
456
const props = shallowReadonly ( { n : { foo : 1 } } )
Original file line number Diff line number Diff line change @@ -197,7 +197,14 @@ export const mutableHandlers: ProxyHandler<object> = {
197
197
198
198
export const readonlyHandlers : ProxyHandler < object > = {
199
199
get : readonlyGet ,
200
- set ( target , key ) {
200
+ set ( target , key , value , receiver ) {
201
+ // is computed()
202
+ if ( ( target as any ) . __v_isRef && ( target as any ) . effect ) {
203
+ // computed should be able to set its own private properties
204
+ if ( key === '_dirty' || key === '_value' ) {
205
+ return set ( target , key , value , receiver )
206
+ }
207
+ }
201
208
if ( __DEV__ ) {
202
209
console . warn (
203
210
`Set operation on key "${ String ( key ) } " failed: target is readonly.` ,
You can’t perform that action at this time.
0 commit comments