-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any Examples on Async Actions (not really an issue) #26
Comments
Hi @brownpixel But briefly: A simple example is: store.dispatch(creator.reload());
new Thread(() -> {
try {
SomeData data = loadFromNetwork();
store.dispatch(creator.dataLoaded(data));
} catch (Exception e) {
store.dispatch(creator.dataLoadingFailed(e));
}
}).start(); What you need to do is to define proper handlers for these three actions (reload, loading succeeded, loading failed). Inside reducer, you know how to manage loading flag or other things based on those actions. The example above is pretty simple but effective. But I usually prefer to use RxJava to handle all the async work. There is https://github.com/Yarikx/reductor/tree/master/reductor-observable project to do that. The idea is also simple: You have some Epic<String> pingPongEpic = (actions, store) ->
actions.filter(Epics.ofType("PING"))
.delay(1, TimeUnit.SECONDS)
.map(action -> Action.create("PONG")); You can find more information looking for https://redux-observable.js.org/ documentation or examples, as Ask if you need more help. |
@brownpixel |
@Yarikx @colorhaake Thanks for the replies and suggestions. I guess you are right in the sense that there is no async actions...was thinking more of an action creator that processes stuff then returns a callback action that runs through the reducer then returns a state. That way you can nicely do some progress dialogs that show/dismiss while this "async" action does its thing...To get an idea you can check out ReSwift's implementation here https://github.com/ReSwift/ReSwift/blob/master/ReSwift/CoreTypes/Store.swift Anyways for now I resorted to RxJava and some state variables that indicate whether things went successfully or not Thanks again |
@brownpixel If I understood the idea it returns callback when you dispatch an action, am I correct? If so, similar approach is used in some redux libraries. By default This approach is good enough but it introduces one problem into particular Reductor implementation -- type safety. In our case, we need to know exactly what Another option is to simply return Object from For exactly that reason I've made But if you want a bit more fancy action creator you can do it yourself: |
Is there an easy way to install the epic other than import it as a submodule? NVM, I found the jcenter repo. Thanks. :) |
Hello
Great library. Wondering if there are any examples where you leverage the library's ability to do async actions?..i.e an action where the initiating view can listen to a callback to handle ui changes. Say for instance an action that requires some networking to be achieved and to show/remove a progress indicator while this is being completed
The text was updated successfully, but these errors were encountered: