|
|
|
|
|
by acemarke
3294 days ago
|
|
I'm still not sure exactly what you're trying to say there, particularly by "push Redux to solve these async problems". Redux itself is about synchronous state updates, as inspired by the Flux Architecture. Because of that, async behavior and side effects are handled via middleware. Most developers are not overly comfortable with FP concepts or code. Redux was intended as a lightweight intro to FP principles, and React also helps push people in that direction. Even fewer people are comfortable with observables, although Angular is maybe starting to change that somewhat. So, it's not just about "better suited abstractions", it's about what developers understand and can use well. To be honest, your comments seem to be leaning towards the common stereotype of an FP enthusiast: "This approach is clearly superior and correct, why would people do anything else?" |
|
It shouldn't be though. The middleware pattern makes a lot of sense for transforming data (communication between mismatched APIs etc), or using it in some way before passing it on (logging, analytics etc). IMO it's totally wrong for this use case though.
All redux-thunk is doing is taking some "action", clobbering it, pretending it doesn't exist, and running some arbitrary function that it's passed.
dispatch(higherOrderFunctionThatCreatesAsyncFunction())
is identical to
asyncFunction()
What people are looking for is some way to get the data store dependencies into asyncFunction in a testable way. This can easily be done without middleware.