Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(reactivity): unwrap value when using set (#722)
  • Loading branch information
pikax committed Jun 4, 2021
1 parent 2c342d5 commit bd198e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/reactivity/set.ts
Expand Up @@ -34,7 +34,8 @@ export function set<T>(target: any, key: any, val: T): T {
return val
}
if (!ob) {
target[key] = val
// If we are using `set` we can assume that the unwrapping is intended
defineAccessControl(target, key, val)
return val
}
defineReactive(ob.value, key, val)
Expand Down
12 changes: 12 additions & 0 deletions test/ssr/ssrReactive.spec.ts
Expand Up @@ -90,4 +90,16 @@ describe('SSR Reactive', () => {

done()
})

// #721
it('should behave correctly', () => {
const state = ref({ old: ref(false) })
set(state.value, 'new', ref(true))
// console.log(process.server, 'state.value', JSON.stringify(state.value))

expect(state.value).toMatchObject({
old: false,
new: true,
})
})
})

0 comments on commit bd198e7

Please sign in to comment.