You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to know what would be the best way to scope an action with some info from the state.
Let's say we have a list and a row. The row has an action "tap". This list is integrated then in a bigger module, let's call it "App". This "App" module would take actions from different smaller modules and react to those. Right now what I'm doing is this: in the appReducer I check all the individual actions from all the app submodules, I get all the "tap" actions, and then I extract the model in each case. This doesn't make much sense to me, since the appReducer needs to know about all specific individual substates.
My idea to solve this would be to have a "scope" function of the "Store", like this:
This way I could take the model from the row action "tap", and transform it to the list action.
Sorry if it's not clear, it's harder to explain than I thought. Would this be possible? Is there a better way that I don't see?
Another option that I see is using the reducer, which does have access to both the state and the action, and sending a different action, but I'm not sure I like this, since it means I have two actions that need to be sent through all the reducers, and I'm not sure how that might affect performance.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to know what would be the best way to scope an action with some info from the state.
Let's say we have a list and a row. The row has an action "tap". This list is integrated then in a bigger module, let's call it "App". This "App" module would take actions from different smaller modules and react to those. Right now what I'm doing is this: in the appReducer I check all the individual actions from all the app submodules, I get all the "tap" actions, and then I extract the model in each case. This doesn't make much sense to me, since the appReducer needs to know about all specific individual substates.
My idea to solve this would be to have a "scope" function of the "Store", like this:
public func scope<LocalState, LocalAction>( state toLocalState: @escaping (State) -> LocalState, action fromLocalAction: @escaping (LocalState, LocalAction) -> Action ) -> Store<LocalState, LocalAction> {
This way I could take the model from the row action "tap", and transform it to the list action.
Sorry if it's not clear, it's harder to explain than I thought. Would this be possible? Is there a better way that I don't see?
Another option that I see is using the reducer, which does have access to both the state and the action, and sending a different action, but I'm not sure I like this, since it means I have two actions that need to be sent through all the reducers, and I'm not sure how that might affect performance.
Beta Was this translation helpful? Give feedback.
All reactions