Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(runtime-core): unwrap nested refs on the component #738

Closed
wants to merge 1 commit into from

Conversation

pikax
Copy link
Member

@pikax pikax commented Feb 18, 2020

The commit 6b10f0c broke the auto-unwrap when the reference is in the middle of the object, added tests to cover some more cases.

  it('should expose return values to template render context', () => {
    const Comp = defineComponent({
      setup() {
        return {
          // ref should auto-unwrap
          ref: ref('foo'),
          // object exposed as-is
          object: reactive({ msg: 'bar' }),
          // primitive value exposed as-is
          value: 'baz',
          // nested ref at the end should auto-unwrap
          nested: { ref: ref('qux') },
          // ref with nested should auto-unwrap
          refNested: ref({
            nested: {
              ref: ref('foo')
            }
          }),
          // nested ref in the middle should auto-unwrap
          refMiddleNested: {
            nested: ref({
              msg: 'bar'
            })
          }
        }
      },
      render() {
        return `${this.ref} ${this.object.msg} ${this.value} ${
          this.nested.ref
        } ${this.refNested.nested.ref} ${this.refMiddleNested.nested.msg}`
      }
    })
    expect(renderToString(h(Comp))).toMatch(`foo bar baz qux foo bar`)
  })

@pikax
Copy link
Member Author

pikax commented Feb 18, 2020

@yyx990803 Just read the commit message from the commit I mentioned... Making this PR invalid, but also making the typescript typings (unwrapped ) invalid also.

On the example above the correct access to the properties is:

`${this.ref} ${this.object.msg} ${this.value} ${this.nested.ref.value} ${this.refNested.nested.ref} ${this.refMiddleNested.nested.value.msg}`

But the current recursive unwrap, makes the typescript throwing an error on that. The documentation is also misleading, it should be updated to reflect the new behaviour.

@yyx990803 yyx990803 closed this in a840e7d Feb 19, 2020
@pikax pikax deleted the feat/bring-back-nested-unwrap branch February 20, 2020 08:51
pikax added a commit to pikax/vue-composable that referenced this pull request Feb 20, 2020
pikax added a commit to pikax/vue-composable that referenced this pull request Feb 21, 2020
* feat(validation): Add validation

* improve validation

* improvement on validate and add example

* fix validate example

* improve validation, track dependencies on validate

* convert the return to reactive, this will allow the render to not required `.value` at the end

vuejs/core#738

* improve test coverage

* WIP add validation docs

* validation docs

* added validation to readme and changelog

* add warning to validation docs
@yyx990803
Copy link
Member

FYI this behavior will be reverted in the next release (back to implicit deep unwrap)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants