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
This is neat! And for non-async getter/loader functions this would enable simplifying some of my Reducers where I otherwise emit a viewDidAppear ViewAction from the View and perform the loading in the reducer.
I guess my question is really: is there any best practice for loading some initial values using dependencies? Maybe some better pattern than viewDidAppear ViewAction?
Feels like init of State is a good place, but also since Reducer protocol, potentially init of the Reducer itself? Hmm nah better to do it in State directly. And would be awesome to support async! hmm maybe it would work to do Task { self.valueFoo = try? await fooClient.get() }, hmm would that work? But one should probably rely on actions here, which we do not have access to from State but from Reducer, so maybe Reducer init is preferable? Because one wants probable to dispatch a getFooResult(TaskResult<Foo>) action to the reducer.
Do you all use viewDidAppear from View with ViewAction.didAppear -> load data with dependency in Reducer? Or have you come up with any neat improvements?
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.
-
Two weeks ago PR https://github.com/pointfreeco/swift-composable-architecture/pull/1620/files was merged, it contains a test in which the State of a Reducer declares a @dependency in the body of the State reducer to set a value.
This is neat! And for non-async getter/loader functions this would enable simplifying some of my Reducers where I otherwise emit a viewDidAppear ViewAction from the View and perform the loading in the reducer.
I guess my question is really: is there any best practice for loading some initial values using dependencies? Maybe some better pattern than viewDidAppear ViewAction?
Feels like init of State is a good place, but also since Reducer protocol, potentially init of the Reducer itself? Hmm nah better to do it in State directly. And would be awesome to support async! hmm maybe it would work to do
Task { self.valueFoo = try? await fooClient.get() }
, hmm would that work? But one should probably rely on actions here, which we do not have access to from State but from Reducer, so maybe Reducer init is preferable? Because one wants probable to dispatch agetFooResult(TaskResult<Foo>)
action to the reducer.Do you all use viewDidAppear from View with ViewAction.didAppear -> load data with dependency in Reducer? Or have you come up with any neat improvements?
Beta Was this translation helpful? Give feedback.
All reactions