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:
```js
if(!Promise.allSettled) {
Promise.allSettled = function(promises) {
return Promise.all(promises.map(p => Promise.resolve(p).then(value => ({
status: 'fulfilled',
value
}), reason => ({
status: 'rejected',
reason
}))));
if (!Promise.allSettled) {
const rejectHandler = reason => ({ status: 'rejected', reason });
const resolveHandler = value => ({ status: 'fulfilled', value });
Promise.allSettled = function (promises) {
const convertedPromises = promises.map(p => Promise.resolve(p).then(resolveHandler, rejectHandler));
return Promise.all(convertedPromises);
};
}
```