-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Sub-structuring #4995
Sub-structuring #4995
Conversation
-1 for "Excluded properties". I don't think we should introduce new syntax, instead we should use e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, as usual
src/nodes.coffee
Outdated
getProps = (props) => (p for p in @finalProps @objProperties props) | ||
for prop in props | ||
if prop instanceof Obj | ||
ret = [ret..., (getProps prop.properties)...] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we usually write calls getProps(prop.properties)
src/nodes.coffee
Outdated
|
||
finalProps: (props = []) -> | ||
ret = [] | ||
getProps = (props) => (p for p in @finalProps @objProperties props) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the for/in here? it's not here L792
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I forgot to remove it. It's a leftover from the previous version.
I agree with @vendethiel regarding the "Excluded properties". |
Nice work @zdenko ! Soo I'm just looking at what babel ends up doing when you destructure with
So basically it will throw an error if the key doesn't exist, which imho is a poor design choice by the tc39 folks. The only use that it provides is basically a shorthand for validation. The reason I like the That's not to say we should prevent folks from doing the {a:{}} syntax, but at least this way people can have an option to be deliberate about throwing runtime errors. Note that regular destructuring does not cause babel to check that something is defined (i.e. |
@aminland |
Sorry to join this discussion so late, I’m just starting to wrap my head around this. To take your initial example: data =
title: "Mr"
name: "Coffee"
address: "Sesame Street"
view = data{title, name:full_name}
# view = { title: "Mr", full_name: "Coffee" } So the view = Object.assign {}, {title: data.title, full_name: data.name} Which gives me two questions:
|
This syntax is the same as assigning to new variable names in object destructuring, i.e. the new name is on the right side. o = {p: 42, q: yes}
{p: foo, q: bar} = o
# foo = 42, bar = yes |
Yeah I think JS kind of messed up by choosing that syntax... but since it's already been implemented in CS and it's here to stay, we have to go with it. The idea here is that it's not a new syntax really, as much as it is an extension of the existing destructuring syntax to make it more useful. @GeoffreyBooth to answer your question 1, I certainly think so. Often (esp. for react components) I'm finding myself having to extract and pass through dozens of props all the time, and this gets very tedious. |
Closing for now per #4991 (comment) |
This PR adds features proposed in #4991: assigning properties from one object into another object (i.e. building / extending objects).