refactor(runtime-core): revert setup() result reactive conversion

BREAKING CHANGE: revert setup() result reactive conversion

    Revert 6b10f0c & a840e7d. The motivation of the original change was
    avoiding unnecessary deep conversions, but that can be achieved by
    explicitly marking values non-reactive via `markNonReactive`.

    Removing the reactive conversion behavior leads to an usability
    issue in that plain objects containing refs (which is what most
    composition functions will return), when exposed as a nested
    property from `setup()`, will not unwrap the refs in templates. This
    goes against the "no .value in template" intuition and the only
    workaround requires users to manually wrap it again with `reactive()`.

    So in this commit we are reverting to the previous behavior where
    objects returned from `setup()` are implicitly wrapped with
    `reactive()` for deep ref unwrapping.
This commit is contained in:
Evan You
2020-02-26 19:01:42 -05:00
parent 11d2fb2594
commit e67f655b26
3 changed files with 11 additions and 46 deletions

View File

@@ -4,7 +4,6 @@ import {
defineComponent,
PropType,
ref,
Ref,
reactive,
createApp
} from './index'
@@ -65,15 +64,12 @@ describe('with object props', () => {
// setup context
return {
c: ref(1),
d: reactive({
d: {
e: ref('hi')
}),
},
f: reactive({
g: ref('hello' as GT)
}),
h: {
i: ref('hi')
}
})
}
},
render() {
@@ -106,9 +102,6 @@ describe('with object props', () => {
expectType<string>(this.d.e)
expectType<GT>(this.f.g)
// should not unwrap refs nested under non-reactive objects
expectType<Ref<string>>(this.h.i)
// setup context properties should be mutable
this.c = 2