Closed BlackHole1 closed 6 years ago
if resolve
and reject
handle almost the same. I think this is very necessary. Because it can simplify a lot of unnecessary code.
Translation for Google. It may not be very well worded. Please forgive me.
I do think this is an interesting use case. We need a very good reason for adding additional non-standard methods though, and I don't think this is a sufficiently large problem that we should include another non-stanadard method in this implementation.
A workaround like this seems good enough to me:
promise.then(
data => ({state: true, data}),
data => ({state: false, data}),
).then(({state, data}) => {
const msg = state ? 'operation successful' : 'operation failed'
console.log(
state,
data,
msg
)
})
I wrote a package to enhance Promise
https://www.npmjs.com/package/promise-unified
Can you add this description to the README.md?
Because I think some people will use this method. I think it's not very intuitive to add the then
method on the basis of the original.
Promise lacks an unified operation method
Core:
Use:
If it was before, then it should be done:
It is less coordinated to do this, I think it would be better to add the
unified
method