3 ms·
If I do the following: let visFilter = 'foo'; const newState = match (action) { {type: 'set-visibility-filter', filter: visFilter} => console.log(visFi
by xodeus 8y ago
If I do the following:
let visFilter = 'foo';
const newState = match (action) {
{type: 'set-visibility-filter', filter: visFilter} => console.log(visFilter)
}
What happens?
Is it checking if action.type === 'set-visibility-filter' && action.filter === 'foo' or is it destructuring the value of action.filter into visFilter?
- always_good 8y agoEvery example in on the readme demonstrates that using an identifier in that position becomes destructured assignment.
- xodeus 8y agofound the answer in the full proposal. Variables will always be assigned to, never checked for equality. To me this is pretty average and seems like it will cause magic numbers/strings/etc if I can't use constants where it makes sense. The proposed solution is to do something like { status: 200 } if (x === foo) => // do something which just seems (for this type of use case, maybe not all) like more boilerplate code for no real benefit over just doing something like if (res.status === 200 && res.x === foo) //do something I would much prefer if there was some sort of special operator used to either check equality or to destructure when matching so it is obvious what the code is doing.