Closed zpbc007 closed 1 year ago
@zpbc007 The onChange
modifier only applies to the reducer you chain onto it with. So in this case. the Reduce
. If you want it to apply to the all of the child reducers, you must first combine them using CombineReducers
(or in their own conformance/builder):
+CombineReducers {
Scope(state: \.childState, action: /Action.child) {
ChildFeature()
}
Reduce {state, action in
switch action {
case .add:
state.parentNumber += 1
return .none
case .child:
return .none
}
}
+}
.onChange(of: \.parentNumber) { oldValue, newValue in
Reduce { state, action in
state.latestInfo = "oldValue: \(oldValue), newValue: \(newValue)"
return .none
}
}
Since this isn't a bug with the library, I'm going to convert it to a discussion.
Description
onChange not work for state change by setter.
Checklist
main
branch of this package.Expected behavior
onChange should trigger when the parentNumber changed
Actual behavior
onChange only trigger when the parentNumber changed by ParentFeature,when ChildFeature change it's number, ParentFeature.State.number changed but onChange not fire
Steps to reproduce
The Composable Architecture version information
No response
Destination operating system
No response
Xcode version information
No response
Swift Compiler version information
No response