This PR deprecates the publisher property for the StateContainer class and the @ViewState and @RenderedViewState property wrappers. It replaces the publisher property with two new properties called willSetPublisher and didSetPublisher that more accurately and explicitly indicate the publisher's timing.
Reasoning
During early use of the new @ViewState and @RenderedViewState property wrappers, it was discovered that when observing the state changes in a SwiftUI view via onReceive, the body property had already been evaluated for this state change because it was happening on the underlying StateContainer's willSet event. This means that if an engineer then modifies any SwiftUI view property (i.e., @State, @ObservedObject, etc.) it will cause the body property to be reevaluated, wasting resources and potentially causing timing bugs. In cases where the view state is progressed within the onReceive property, is is possible to cause infinite recursion.
As a result, the willSet and didSet event publishers were created so that engineers could have more fine-grained control over the timing of the state observation code.
Description
This PR deprecates the
publisher
property for theStateContainer
class and the@ViewState
and@RenderedViewState
property wrappers. It replaces thepublisher
property with two new properties calledwillSetPublisher
anddidSetPublisher
that more accurately and explicitly indicate the publisher's timing.Reasoning
During early use of the new
@ViewState
and@RenderedViewState
property wrappers, it was discovered that when observing the state changes in a SwiftUI view viaonReceive
, thebody
property had already been evaluated for this state change because it was happening on the underlying StateContainer'swillSet
event. This means that if an engineer then modifies any SwiftUI view property (i.e.,@State
,@ObservedObject
, etc.) it will cause thebody
property to be reevaluated, wasting resources and potentially causing timing bugs. In cases where the view state is progressed within theonReceive
property, is is possible to cause infinite recursion.Example Problem Scenario (Credit: @mlarandeau)
As a result, the willSet and didSet event publishers were created so that engineers could have more fine-grained control over the timing of the state observation code.
Type of Change
Checklist