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 want to separate logics when fetchData() is executed in actionA and when fetchData() is executed in actionB.
case .actionA:
return .task{return.fetchResponse(awaitfetchData())}
case .actionB:
return .task{return.fetchResponse(awaitfetchData())}
case let.fetchResponse(data):
// if data from actionA
// state.xxx = someLogicForA()
// if data from actionB
// state.xxx = someLogicForB()
I have come up with two methods, but I would like to know if there is a better way.
case .actionA:...
return .task{return.fetchResponseInActionA(awaitfetchData())}
case .actionB:...
return .task{return.fetchResponseInActionB(awaitfetchData())}
case let.fetchResponseInActionA(data):state.xxx=someLogicForA()
return .none
case let.fetchResponseInActionB(data):state.xxx=someLogicForB()
return .none
The other way:
enumFetchResponseType:Equatable{case inActionA
case inActionB
}enumAction:Equatable{case fetchResponse(SomeData,FetchResponseType)}
case .actionA:...
return .task{return.fetchResponse(awaitfetchData(),.inActionA)}
case .actionB:...
return .task{return.fetchResponse(awaitfetchData(),.inActionB)}
case let.fetchResponse(data,.inActionA):state.xxx=someLogicForA()
return .none
case let.fetchResponse(data,.inActionB):state.xxx=someLogicForB()
return .none
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 want to separate logics when
fetchData()
is executed in actionA and whenfetchData()
is executed in actionB.I have come up with two methods, but I would like to know if there is a better way.
The other way:
Beta Was this translation helpful? Give feedback.
All reactions