Replies: 1 comment 1 reply
-
you can listen to BindingState of a ViewState in the reducer like the following: Reduce { state, action in
case .binding(\.view.$isToggled):
print(state.isToggled)
return .none
// ....
} also you need to extend your reducer's Action (Toggle Reducer in your case) extension Toggle.Action {
init(action: ToggleView.ViewAction) {
switch action {
case let .binding(binding):
self = .binding(binding.pullback(\.view))
}
}
} finally your ViewStore's init should be |
Beta Was this translation helpful? Give feedback.
1 reply
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.
-
Hey everyone,
I was currently migrating one of my apps to
prerelease/1.0
(I was on version0.9.0
, so there were a few updates needed 😅) and stumbled on something I thought was kind of weird (I don't think this is related to version 1.0 though).To give some context I have the following structure (simplified):
So the idea of it is that I have a view with a Toggle in it, which when enabled would show a child-view. To achieve this I have some
ViewState
so I only update theToggleView
when the toggle itself has changed. Then in the Reducer I have aBindingReducer
and a customReduce
where I also change some state given the new state of the toggle.The issue is inside this
Reduce
part, I'm trying to intercept.binding(.set(\.$isToggled, true/false))
but I never get this event, digging a bit more on it, I realised that invar domainAction: Toggle.Action
I useaction.pullback(\.view)
which transforms the event into.binding(.set(\.view.$isToggled, true/false))
(notice the.view
path prepended) which makes sense, but since I havevar view: ToggleView.ViewState
as a private extension in theToggleView
file, theReducer
doesn't have access to it (I'd like to keep it that way tbh so theReducer
is not coupled to theView
).I found a workaround where I could change how I map the
domainAction
and not use the.pullback()
method, like this:My
Reduce
starts working as expected, but I get the following message in the console:So I was wondering if there is some other way of achieving what I want here without having the message spamming the logs on debug?
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions