look like ninja code

It can be more readable with same line of code. There was a lot of nested parenthesis.
This commit is contained in:
Mustafa Kemal Tuna 2020-11-10 15:45:14 +03:00 committed by GitHub
parent 26b393a7d8
commit a4194ceeff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -176,15 +176,14 @@ So for each promise we get its status and `value/error`.
If the browser doesn't support `Promise.allSettled`, it's easy to polyfill: If the browser doesn't support `Promise.allSettled`, it's easy to polyfill:
```js ```js
if(!Promise.allSettled) { if (!Promise.allSettled) {
Promise.allSettled = function(promises) { const rejectHandler = reason => ({ status: 'rejected', reason });
return Promise.all(promises.map(p => Promise.resolve(p).then(value => ({
status: 'fulfilled', const resolveHandler = value => ({ status: 'fulfilled', value });
value
}), reason => ({ Promise.allSettled = function (promises) {
status: 'rejected', const convertedPromises = promises.map(p => Promise.resolve(p).then(resolveHandler, rejectHandler));
reason return Promise.all(convertedPromises);
}))));
}; };
} }
``` ```