-
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
CS2 Discussion: Features: Support splats in object literals (object rest/spread syntax) #4959
Comments
From @JavascriptIsMagic on 2016-12-15 20:41 I've been seeing object spread being recommended and I've seen it being used heavily in large production code bases. I find myself using I think this does require you to use the fun a: 1, b... # ambiguous
fun {a: 1, b...} # unambiguous Also do we go with the spec and put the operator on the left One benefit to having it go in the opposite direction would be that it could disambiguate the two and we could get rid of the need for # object spread:
fun a: 1, ...b # fun({ a: 1, ...b })
# argument spread:
fun a: 1, b... # fun({ a: 1 }, ...b) Though consistency of the spread syntax might be preferred over getting rid of ambiguity. |
From @connec on 2016-12-15 21:07 I'd definitely vote for consistency over that ambiguity, though it is an annoying one. Ultimately I suppose it's consistent with needing explicit braces to have shorthand objects in arguments lists too. f a: a, b # f({ a: a }, b)
f { a: a, b } # f({ a: a, b: b }) |
From @YamiOdymel on 2017-02-22 15:41 I'd recommend to put the so you can spread an object from the function like this (This is very common in Vuex, Redux): export default {
name: 'CounterBlock'
methods:
...mapActions
increment : counter.actions.increment,
set : counter.actions.set,
fetchCount: counter.actions.fetchCount
computed:
...mapGetters
total: counter.getters.total
} currently with export default {
name: 'CounterBlock'
methods: Object.assign {}, mapActions
increment : counter.actions.increment,
set : counter.actions.set,
fetchCount: counter.actions.fetchCount
computed: Object.assign {}, mapGetters
total: counter.getters.total
} with export default {
name: 'CounterBlock',
methods: {
...mapActions({
increment : counter.actions.increment,
set : counter.actions.set,
fetchCount: counter.actions.fetchCount
})
},
computed: {
...mapGetters ({
total: counter.getters.total
})
},
} |
From @GeoffreyBooth on 2017-07-25 05:28 Added via #4493 |
From @chabib on 2017-10-14 18:51 @GeoffreyBooth @YamiOdymel
|
From @YamiOdymel on 2017-10-14 19:13 @chabib Well, if I'm not mistaken, you could use it like this. object = {
...mapActions
increment : counter.actions.increment,
set : counter.actions.set,
fetchCount: counter.actions.fetchCount
} Which produces: var object, _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
object = _extends({}, mapActions({
increment: counter.actions.increment,
set: counter.actions.set,
fetchCount: counter.actions.fetchCount
})); is the same as below with object = {
...mapActions({
increment : counter.actions.increment,
set : counter.actions.set,
fetchCount: counter.actions.fetchCount
})
} |
From @chabib on 2017-10-14 19:25 Thank you @YamiOdymel !
But not this
|
From @YamiOdymel on 2017-10-14 19:42 @chabib I asked about this in #4449
|
From @connec on 2016-12-15 18:31
I would love to see object spreads and rests supported via splats in object literals:
Compilation in the
2
branch could happily useObject.assign
for construction:Destructuring would require more implementation, e.g.
We could alternatively wait for the proposal to land in environments, or rely on a transpiler like babel.
The text was updated successfully, but these errors were encountered: