Useful topic and nice post, great job!
Indeed promise nesting is widespread among novice developers.
In my opinion it happens coz Promise.then() still considered as a hook to attach callback on certain 'event' (as we did with callbacks) and the fact that Promise.then() RETURNS something is often missed.
Btw, just had a crazy idea. I think it might be better if a callback in Promise.then() must explicitly returns only promise (if you want to return value - Promise.resolve(100)) to avoid complexity with implicit wrapping.
Well, it can help alleviate the confusion, but I recommend reading my recent article on best practices for ES6 promises. In it, I explained why it's best to refrain from wrapping values in promises as much as possible. I particularly discouraged the use of Promise.resolve, so I think that might be worth your read. 😉
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Useful topic and nice post, great job!
Indeed promise nesting is widespread among novice developers.
In my opinion it happens coz Promise.then() still considered as a hook to attach callback on certain 'event' (as we did with callbacks) and the fact that Promise.then() RETURNS something is often missed.
Btw, just had a crazy idea. I think it might be better if a callback in Promise.then() must explicitly returns only promise (if you want to return value - Promise.resolve(100)) to avoid complexity with implicit wrapping.
Best Practices for ES6 Promises
Basti Ortiz (Some Dood) ・ Jul 22 ・ 8 min read
Well, it can help alleviate the confusion, but I recommend reading my recent article on best practices for ES6 promises. In it, I explained why it's best to refrain from wrapping values in promises as much as possible. I particularly discouraged the use of
Promise.resolve
, so I think that might be worth your read. 😉