Redux and within a gearbox accessing another gearbox, how?

So, I have an application that has several reducers and, therefore, several action creators are connected.

There is a time when one of my gearboxes updates the state (due to editing), and so I have to make sure that other gearboxes see this update and adjust their status accordingly.

think of it as if the user selects "running shoes" and this state control is located in a gearbox called productsReducer. That way, as the user navigates through the application process, they get the couponsReducer associated with it ... but the user can “edit” at any time, so if they then edit the “sneakers” and say, select another producer, I should be able to change couponsReducer in real time, because the modality of progress should reflect this. I can do this by going through the stream to the coupon page, because on this page I just compare the data with componentWillMount ... but I have modal progress in my hand, and before going to the coupon page, the user can open the modality ... and here will be missmatch ...

I know, I just wanted to explain my situation.

so I want to be able to call "other reducers" or their action creators from within the Reducer product.

Would middleware be appropriate here in which I sniff for a specific “action.type” and if I see it, can I send another action.type file or is there a way to call action creators from productsReducer?

importing: import * as coupons from. / couponsActions and any other actions that seem inappropriate to me.

+4
source share
2 answers

The state of the update based on the state of the application is an anti-pattern. The solution is even simpler:

, , .

, sneakers,

{ type: 'item_select', payload: 'sneakers' }

couponsReducer, :

function (state == initialState, action) {
  if (action.type == 'item_select') {
    return { ...state, activeProduct: action.payload);}
  }
  return state;
}

, . , .

+11

( ). .

, . , redux-saga, :

function* watchItemSelect() {
    while(true) {
        // Wait for the action you are interested in
        const action = yield take('ITEM_SELECT');
        // Send another action
        yield put({type: 'OTHER_ACTION'}) 
        // The loop will now continue and wait until the next ITEM_SELECT action comes
    }
}

, , . :

:

redux-architecture

+1

All Articles