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

handle rest elements in computed properties #1628

Merged
merged 1 commit into from
Aug 4, 2018
Merged

handle rest elements in computed properties #1628

merged 1 commit into from
Aug 4, 2018

Conversation

Rich-Harris
Copy link
Member

Alright, let's fix #1540 once and for all. This adds support for rest elements in computed properties. It does so in a way that avoids the props.props.props.props thing we discovered — in a case like this...

computed: {
  foo: ({ x, ...y }) => y
}

...foo will be excluded from the object passed in. This might seem slightly magical, but I think it matches people's intuitions of how this should work.

@Rich-Harris Rich-Harris mentioned this pull request Aug 4, 2018

helpers: {
// prevent this being mixed in with data
JSON
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm I'm not thrilled with having to do this ... Is it practical to change how whitelisted globals work so that they don't get assigned into the component's data? I actually wasn't aware or had forgotten that this was the case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit annoying, yeah, but is by far the easiest way to make globals available. The alternative would be to more cleanly separate state and the root ctx object:

// on init
const base = { JSON };

// on each change
const ctx = assign({}, base, newState);
this._recompute(changed, ctx);

That might be necessary anyway at some point, to work around some other quirks relating to merging store with non-store data, and also this.get({ computed: false }) etc. But I think it's orthogonal to this issue

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.

Object rest support
2 participants