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
Replace ColdSignal and HotSignal with SignalProducer and Signal #1655
Conversation
/// A mutable property of type T that allows observation of its changes. | ||
/// | ||
/// Instances of this class are thread-safe. | ||
public final class Property<T> { |
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 purely a convenience type for binding. It can be implemented entirely in terms of the SignalTemplate.buffer
constructor.
@jacksonh
@andymatuschak pointed out that the Builder pattern refers to something very specific, and this would not be that. |
I kinda like There are also no RAC 2.0 preconceptions around these names, which could people migrating. |
|
public func combinePrevious<T>(initial: T)(signal: Signal<T>) -> Signal<(T, T)> | ||
public func concat<T>(next: Signal<T>)(signal: Signal<T>) -> Signal<T> | ||
public func delay<T>(interval: NSTimeInterval, onScheduler scheduler: DateScheduler)(signal: Signal<T>) -> Signal<T> | ||
public func dematerialize<T>(signal: Signal<Event<T>>) -> Signal<T> |
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.
👍 no more identity
!
/// | ||
/// After an `Error` or `Completed` event has been added to the buffer, the | ||
/// sink will not add any further events. | ||
public static func buffer(capacity: Int) -> (SignalTemplate, SinkOf<Event<T>>) |
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 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.
Looking good. Nice docstring too.
I love it! I agree there's probably a better name than |
@jacksonh Another aspect to the name is whether it's natural to be the subject of |
For some context on the name A better name would be ideal, but this name seemed to meet criteria that the other names didn't, so it has that going for it. |
A few other name ideas (to replace
Out of those, I kinda like “prototype” more than “template.” |
oh my lady gaga,How about SignalT?? |
Prototype has less domain baggage, but also seems less literally correct. I'm 👍 to either. |
In prototype-based languages, a "prototype of an X" is itself usable as an "X." That is to say: one could reasonably expect a |
This helps type inference, but also just makes the various methods for starting clearer.
/// Signals started by the returned producer will not send a value until both | ||
/// inputs have sent at least one value each. | ||
public func combineLatestWith<T, U>(otherSignalProducer: SignalProducer<U>)(producer: SignalProducer<T>) -> SignalProducer<(T, U)> { | ||
return producer.lift(combineLatestWith)(otherSignalProducer) |
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.
How freaking awesome is this?
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.
…emplates Conflicts: ReactiveCocoa/Swift/ColdSignal.swift
Trying to implement everything here was a mistake, since we're basically talking about the whole framework. So, instead, I've annotated outstanding TODOs and would like to merge this as-is (and create smaller PRs into 🙌 |
Gonna #yolo this so I can create dependencies that don't have crazy diffs. |
Replace ColdSignal and HotSignal with SignalProducer and Signal
After the long discussion in #1650, I invited @NachoSoto, @andymatuschak, and @kastiglione to talk more in-depth about the Swift APIs, and specifically where they need improvement.
We had a really, really great brainstorming session, and this is the result. The good news is that we all feel pretty good about this direction, and the bad news is that everything is getting rewritten again.
The important bits are documented on the types themselves, but here’s the handy Quick Start guide of the proposed changes:
HotSignal<T>
will be replaced bySignal<T>
. Besides the name change, these signals can now sendError
andCompleted
events. This avoids a lot of the lifecycle weirdness that has come up with a value-onlyHotSignal
.ColdSignal<T>
will be replaced bySignalProducer<T>
. As the name implies, a signal producer createsSignal
s (via thestart
method). You can kind of think of the relationship as something like:SignalProducer : Signal :: RACSignal : subscription
SignalProducer : Signal :: class : instance
Signal
, but can be lifted to apply toSignalProducer
instead.retry
andrepeat
, are written in terms ofSignalProducer
.The advantages here are:
Signal
, and can be lifted to theSignalProducer
level.I’ll also make some notes in the changes below, to explain more specific things. Please leave feedback if you have it! 🙇