Replies: 1 comment
-
Hey @ytyubox! public struct Stateless<ParentState, ParentAction, Child: ReducerProtocol>: ReducerProtocol
where Child.State == Void {
public let action: CasePath<ParentAction, Child.Action>
public let child: Child
public init<A>(
action: CasePath<ParentAction, A>,
@ReducerBuilder<Void, A> child: () -> Child) where A == Child.Action {
self.action = action
self.child = child()
}
public func reduce(into state: inout ParentState, action: ParentAction) -> EffectTask<ParentAction> {
guard let action = self.action.extract(from: action) else { return .none }
var void: () = ()
return child.reduce(into: &void, action: action).map(self.action.embed)
}
} That being said, this is rather exotic! Please note that this is equivalent to have a bona-fide child domain that has a Scope(state: \.void, action: /Action.someReducer) { SOME_Reducer() } I don't think that this should be a |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Thank you for having
ReducerProtocol
. it is really amazing. I found that I would like to use a direct value from a dependency not in the State, like local storage or CoreData, etc.So I came up with a stateless Reducer, which have @ Dependency to the framework wrapper.
With that, I tried to embed this into a parent Reducer, and then I encountered a problem.
I found In the previous Reducer, we can use
pullback
likeScope
here, but it also require a KeyPath.So I use a dummy computed var so that it satisfies the API.
Scope(state: \.some_State, ....
But I felt I was doing something wrong.
Maybe it can be
Beta Was this translation helpful? Give feedback.
All reactions