Григорий Карелин (2019-05-28T19:13:19.000Z)
grundiss at gmail.com (2019-05-28T19:23:38.308Z)
Here are another examples, where "destructuring picking" I suggest whould be helpful. ==1A Now (redux related) ``` function mapStateToProps({user: {firstName, lastName}, common: {currentPageURL: url}}) { return {firstName, lastName, url}; } ``` ==1B Proposal ``` function mapStateToProps(state) { return {{firstName, lastName from state.user}, {currentPageURL as url from state.common}}; } ``` Shorter! ==2A Now ``` async function saveNewUserName(name) { const {name} = await sendToServer({name}); return {ok: true, payload: {name}}; // oh wait, which name is it again? Argument or response? } ``` == 2B Proposal ``` async function saveNewUserName(name) { const resp = await sendToServer({name}); return {ok: true, {name from response}}; } ``` No accidental shadowing. I know, I know, you can achieve all that without new syntax, via naming your variables properly and using long explicit expressions. But I think some sugar won't hurt. After all, remember destructuring? There's no reason to use it other than it's cool and short and expressive. And as Bob has mentioned above I'm trying to reuse existing keywords. The question about using curlies around picking. First, it's the way to tell interpreter/transpiler that it's picking operation, second, it's the way to tell where to pick from when doing several picking into one object from different destinations.