Skip to content

Commit 9468f72

Browse files
authored
fix: toRaw typo (#429)
1 parent 94d4d87 commit 9468f72

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

src/mixin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ export function mixin(Vue: VueConstructor) {
222222
if (isPlainObject(binding)) {
223223
const bindingObj = binding
224224
vmStateManager.set(vm, 'rawBindings', binding)
225+
225226
Object.keys(binding).forEach((name) => {
226227
let bindingValue = bindingObj[name]
227228
// only make primitive value reactive
@@ -243,6 +244,7 @@ export function mixin(Vue: VueConstructor) {
243244
}
244245
asVmProperty(vm, name, bindingValue)
245246
})
247+
246248
return
247249
}
248250

src/reactivity/reactive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ export function markRaw<T extends object>(obj: T): T {
269269
}
270270

271271
export function toRaw<T>(observed: T): T {
272-
if (isRaw(observe) || !Object.isExtensible(observed)) {
272+
if (isRaw(observed) || !Object.isExtensible(observed)) {
273273
return observed
274274
}
275275

src/reactivity/unwrap.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ export function unwrapRefProxy(value: any, map = new WeakMap()) {
2929

3030
// copy __ob__
3131
if (value.__ob__) {
32-
Object.defineProperty(obj, '__ob__', value.__ob__)
32+
Object.defineProperty(obj, '__ob__', {
33+
enumerable: false,
34+
value: value.__ob__,
35+
})
3336
}
3437

3538
for (const k of Object.keys(value)) {

test/setup.spec.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
reactive,
99
toRefs,
1010
markRaw,
11+
toRaw,
1112
} = require('../src')
1213

1314
describe('setup', () => {
@@ -548,6 +549,8 @@ describe('setup', () => {
548549
expect(
549550
JSON.parse(vm.$el.querySelector('#refList').textContent)
550551
).toMatchObject([{ value: '1' }, { value: '2' }, { value: '3' }])
552+
553+
expect(warn).not.toHaveBeenCalled()
551554
})
552555

553556
test('nested', () => {
@@ -614,6 +617,8 @@ describe('setup', () => {
614617
expect(vm.$el.querySelector('#nested_aaa_b').textContent).toBe('aaa')
615618
expect(vm.$el.querySelector('#nested_aaa_bb_c').textContent).toBe('aaa')
616619
expect(vm.$el.querySelector('#nested_aaa_bb_cc').textContent).toBe('aaa')
620+
621+
expect(warn).not.toHaveBeenCalled()
617622
})
618623

619624
it('recursive', () => {
@@ -671,6 +676,8 @@ describe('setup', () => {
671676
expect(
672677
vm.$el.querySelector('#recursive_b_recursive_recursive_r').textContent
673678
).toBe('r')
679+
680+
expect(warn).not.toHaveBeenCalled()
674681
})
675682

676683
// #384
@@ -695,10 +702,14 @@ describe('setup', () => {
695702
value: 'r',
696703
},
697704
})
705+
706+
expect(warn).not.toHaveBeenCalled()
698707
})
699708

700709
// #392
701710
it('should copy __ob__ and make toRaw work when passing via props', () => {
711+
let propsObj = null
712+
702713
const Foo = {
703714
template: '<p>{{obj.bar}}</p>',
704715
props: {
@@ -708,7 +719,7 @@ describe('setup', () => {
708719
},
709720
},
710721
setup(props) {
711-
expect(toRaw(props.obj)).toEqual({ bar: 1 })
722+
propsObj = toRaw(props.obj)
712723
return {}
713724
},
714725
}
@@ -722,6 +733,9 @@ describe('setup', () => {
722733
}).$mount()
723734

724735
expect(vm.$el.textContent).toBe('1')
736+
expect(propsObj).toEqual({ bar: 1 })
737+
738+
expect(warn).not.toHaveBeenCalled()
725739
})
726740
})
727741

0 commit comments

Comments
 (0)