withBreak blocks
sagiv ben giat
sagiv.bengiat at gmail.com
Sat Feb 17 21:13:05 UTC 2018
`else if` would work but it will look kinda nasty if you have deeply nested
validations.
Keep in mind my example was a small and simple.
It's the same as using async await vs .then etc...
*שגיב בן גיאט*
*Sagiv ben giat*
On Sat, Feb 17, 2018 at 11:09 PM, Jacob Pratt <jhprattdev at gmail.com> wrote:
> 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/b40472a7/attachment.html>
More information about the es-discuss
mailing list