Fwd: withBreak blocks
sagiv ben giat
sagiv.bengiat at gmail.com
Sat Feb 17 21:02:22 UTC 2018
I hope I'm on the right medium for this, I would like to propose a language
feature.
withBreak blocks
Well the name might not be the best, but it's just my way to be the most
clear about this feature proposal.
I often find my self doing this in my code:
const doWork = () => {
// try catch omitted for brevity
const response = fetchData();
do {
if (response.error) {
log(response.message);
break;
}
if (!response.data) {
log("No data");
break;
}
if (!response.data.todos) {
log("No Todos");
break;
}
return action({ data: response.data });
} while (false);
};
I'm doing this instead of doing bunch of if / else if / else blocks or
ugly nested if blocks.
What i would like to have is a block that will let me break without being
in a loop context.
Something like this:
withBreak {
if (response.error) {
log(response.message);
break;
}
if (!response.data) {
log("No data");
break;
}
if (!response.data.todos) {
log("No Todos");
break;
}
return action({ data: response.data });
}
This can be a synthetic sugar for do{}while(false) behind the scenes.
Best regards,
Sagiv B.G
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180217/a904caa8/attachment.html>
More information about the es-discuss
mailing list