Replies: 3 comments 10 replies
-
Hey @andwrobs! You should think to In your case, |
Beta Was this translation helpful? Give feedback.
-
@andwrobs Can you share more info about the error and your domain's types? E.g. what does Ah, seeing your "edit" now, have you tried using Scope(state: \.player, action: .self) {
Reduce { state, action in
// core reducer logic
}
.ifLet(\.settings, action: /Action.appDelegate) {
AppDelegateReducer()
}
} Or maybe even: Reduce { state, action in
// core reducer logic
}
.ifLet(\.player.settings, action: /Action.appDelegate) {
AppDelegateReducer()
} |
Beta Was this translation helpful? Give feedback.
-
how do I handle nested Enum ? public struct AppReducer: ReducerProtocol {
public enum State: Equatable {
case login(Login.State)
case home(Home.State)
public init() { self = .login(Login.State()) }
}
public enum Action {
case onAppear
case login(Login.Action)
case home(Home.Action)
case appDelegate(AppDelegateReducer.Action)
case didChangeScenePhase(ScenePhase)
case paymentTransaction(StoreKitClient.PaymentTransactionObserverEvent)
case verifyReceiptResponse(TaskResult<ReceiptFinalizationEnvelope>)
}
public var body: some ReducerProtocol<State, Action> {
StoreKitLogic()
Reduce { state, action in
// what next
Scope(state: /State.home, action: /Action.appDelegate) {
Reduce { state, action in
switch action {
case .appDelegate(.settingsLoaded(.success(let settings))):
// set player.settings
return .none
default:
return .none
}
}
.ifLet(\.settings, action: /Action.appDelegate) {
AppDelegateReducer()
}
}
}
}
// Home
public struct Home: ReducerProtocol {
public enum State: Equatable {
case welcome(Welcome.State)
case word(WordReducer.State)
public init() { self = .welcome(Welcome.State()) }
}
public enum Action {
case onAppear
case welcome(Welcome.Action)
case word(WordReducer.Action)
} How scope work with nested enums? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I was trying to scope a nested property of a child state in a parent feature like so:
^ the above works if I lift up the settings struct into the top level AppFeature struct, and then reference it in scope as "settings" directly (like is shown in isowords and other examples) — but if I try to target just the property of the player child state, it doesn't appear I can get it returning in the KeyPath type I need.
Perhaps there's a way to do the mapping with some ReducerProtocol extensions? Any recommendations for this use case?
Thanks!!
EDIT: settings was an optional property of Player and that seems to be what was causing the issue
Beta Was this translation helpful? Give feedback.
All reactions