withBreak blocks
Jacob Pratt
jhprattdev at gmail.com
Sat Feb 17 21:09:34 UTC 2018
Perhaps I'm missing something, but why wouldn't an `else if` work here?
jhpratt
On Sat, Feb 17, 2018 at 4:02 PM, sagiv ben giat <sagiv.bengiat at gmail.com>
wrote:
> 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
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180217/3c9cf32d/attachment-0001.html>
More information about the es-discuss
mailing list