-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement PropertyType.signal
.
#2622
Conversation
4f122f7
to
c6d3bef
Compare
self.producer = SignalProducer(value: value) | ||
|
||
producer = SignalProducer(value: value) | ||
signal = Signal { observer in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be Signal.empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is only Signal.never
. :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh. Then let's add that! :)
Thanks for tackling this! Can you rebase now that #2617 is merged? |
@@ -135,6 +187,8 @@ public final class MutableProperty<Value>: MutablePropertyType { | |||
private weak var object: NSObject? | |||
private let keyPath: String | |||
|
|||
private var _property: MutableProperty<AnyObject?>? = MutableProperty<AnyObject?>(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type here is redundant.
5715639
to
d0fae54
Compare
Rebased and updated. :-) |
|
||
/// Initializes the property to have the given value. | ||
public init(_ value: Value) { | ||
self.value = value | ||
self.producer = SignalProducer(value: value) | ||
producer = SignalProducer(value: value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use self.xxx = ...
here for consistency?
Rebased and reverted to use
I have added also a few "should yield... even if the value actually remains unchanged" test cases. |
fd9964a
to
c748f26
Compare
29d0fb0
to
2651f6f
Compare
The failing test case is from RACSignalSpec, hmm. All Swift specs passed.
|
@@ -97,6 +109,16 @@ public final class MutableProperty<Value>: MutablePropertyType { | |||
} | |||
} | |||
|
|||
/// A signal that will send the property's changes over time, | |||
/// then complete when the property has deinitialized. | |||
public lazy var signal: Signal<Value, NoError> = { [unowned self] in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine. Eventually I think we should actually expose this from SignalProducer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a SignalProducer.startedSignal
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Feel free to extract that now, but I think we should leave it as internal
for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps just leave it alone then.
Looks perfect! Only thing missing is a test for |
switch event { | ||
case .Interrupted: | ||
signalInterrupted = true | ||
case .Next(_), .Failed(_), .Completed: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto: don't need parenthesis
Awesome |
This is pretty nice! GJ @andersio. @NachoSoto could it be merged (I actually have use case for this)? |
Implement `PropertyType.signal`.
Fixes: #2543
Signal.empty
It is a signal that completes immediately without emitting any value. Future observation to this signal would only result in an
Interrupted
event per theSignal.observe
implementation.ConstantProperty
ConstantProperty.signal
is just aSignal.empty
, since there is never a change anyway.MutableProperty
MutableProperty.signal
is a signal started from the buffering producer at the time the property is initialised.DynamicProperty
DynamicProperty.signal
andDynamicProperty.producer
are backed by an underlyingMutableProperty
. The implementation is not thread-safe (as usual...?).