Skip to content
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

Sample use restapi #141

Open
Avatarchik opened this issue Jul 23, 2020 · 0 comments
Open

Sample use restapi #141

Avatarchik opened this issue Jul 23, 2020 · 0 comments

Comments

@Avatarchik
Copy link

Hi! How can I create a ThunkAction to work with the rest api?
sample:

     public IAction Get(Action.Get action) {
            // return thunk to store, which will dispatch new actions upon success or failure
            return new ThunkAction<State> ((dispatch, getState) => {
                // dispatch first action to set state to loading
                dispatch(new ApiRequestor.Action.GetStart {});

                // use observable to subscribe and dispatch new actions from results
                ObservableWWW
                    .Get(action.url)
                    .Subscribe(
                        successText => {
                            // dispatch second action on success
                            // Debug.Log($"ApiRequestCreator.Get success => dispatching successText: {successText}");
                            dispatch(new ApiRequestor.Action.GetSuccess{
                                text = successText
                            });
                        },
                        failureError => {
                            // dispatch second action on failure
                            // Debug.Log($"ApiRequestCreator.Get failure => dispatching failureError: {failureError}");
                            dispatch(new ApiRequestor.Action.GetFailure{
                                error = failureError
                            });
                        }
                    );
            });
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant