redux-zero / redux-zero

A lightweight state container based on Redux

Home Page:https://matheusml1.gitbooks.io/redux-zero-docs/content/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a way to call an action after another?

opened this issue · comments

If I call an action from another action, the second one completes first.
Is there a way to have the calling action complete first?
Or set it up like, execute action x after action y in sequence?
I think redux-thunk does this but will it work with redux-zero?

Thanks.

How do you call an action from another action ? Could you provide an example ?

For example like this, essentially I call the inner action within outer action. What I want is to schedule the execution of actionInner right after actionOuter. Like it is now it completes first actionInner and then actionOuter.

const actions = (store) => ({
    actionOuter: () => {
        this.actionInner(); //does this work?
        return {outerCompleted:true};
    },
    actionInner: () => {
        return {innerCompleted: true};
    },
}

This is not going to work because in Redux Zero, we only update the state for the last return line.

The only other way to update the state, without using return is to use store.setState.

I'm closing this for now, but if you have more questions regarding this, feel free to ask.

Is this still not working in redux-zero? react-redux supports this with dispatch()
for example, (borrowing the above one)

const actions = (store) => ({
    actionOuter: () => {
        dispatch(actionInner());
        return {outerCompleted:true};
    },
    actionInner: () => {
        return {innerCompleted: true};
    },