29 karma · joined Apr 13, 2015 (11y ago) · 17 submissions
comment 8y ago · link · parent
comment 8y ago · link · parent
One thing I’ve never quite understood about Redux is why we are dispatching pure data instead of a function of state. This would remove the need for reducers, since your action _is_ your reducer. Something like this...
https://gist.github.com/anonymous/a5d741c5dec81be61e0aa70820...
Would this come with any drawbacks? I could see a large application having performance issues because of a large number of function allocations, but for small applications I don’t see a downside, just a simpler API.
comment 9y ago · link · parent
comment 9y ago · link · parent
comment 9y ago · link · parent
comment 10y ago · link · parent
comment 11y ago · link · parent
comment 11y ago · link · parent
They are however, much prettier than regular QR codes. :)
comment 11y ago · link · parent
somethingThatReturnsPromiseWithoutError()
.then((res) => {
return Promise.reject("some error");
})
.catch((err) => {
console.log(err); // => some error
});
Promise.resolve() and Promise.reject() return a promise resolved or rejected to the value passed in the first argument. Returning a promise in the fulfillment function passed to .then() chains the promises together. somethingThatReturnsPromise()
.then((foo) => {
return foo.bar;
// Or if you like it more verbose
return Promise.resolve(foo.bar);
// Or pass bar to a function modifying bar that returns a promise
return modifyBarReturnPromise(foo.bar);
})
.then((newBar) => {
console.log(newBar);
});
In your case, if you need step1Val in next promise chain, I personally do this, however people more familiar with promises may know of a better way to do it (maybe with something like Promise.all() or Promise.props() in the BlueBird library). somethingThatReturnsPromise()
.then((first) => {
doSomethingWithFirstAndReturnPromise(first)
.then((second) => {
console.log(first + second);
});
});