Remove Property source capturing. #117
Merged
+167 −96
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
The PR proposes to have composed properties not retaining its sources. This test case helps illustrate the new behaviour.
Recall that retaining
Propertywould defer the termination of the event stream. Source capturing retains the sources, causing the sources' lifetime being a union with the lifetime of all their derivatives.However, if we consider properties are just streams of values with a stronger guarantee than
Signals (having one latest value), operators - that are fundamentally an observation - should not have a side effect on the observed event stream. In this sense, source capturing should be dropped.It also adds a new initializerProperty(reflecting:), which does the same thing asProperty(_:)but without retaining the supplied property.The default initializer
Property(_:)is changed not to capture the supplied property, while the capturing "existential" variant is renamed toProperty(capturing:). The renaming makes a better migration path when we deprecate the initializer as generalised existential lands in Swift.P.S. Existential properties serves to work around the current language limits, so they should be left untouched.
Background
As brought up in #58 (comment), I have made a review on why we had composed properties capturing its source.
It was originated in ReactiveCocoa/ReactiveCocoa#2788:
It was true at that time, since the property composition operators wasn't a thing yet, and the composition is done through
AnyPropertywhich at that time was based onMutableProperty. So had we not made the property captured, chaining ofmapwould not behave as expected.But now with the property composition formally introduced, we propagate the values using replayed producer, which works properly when chained, rendering the need of capturing moot.