Signal
public final class Signal<Event>
Signal
provides a mechanism for publishing events to subscribers.
-
Initializes a
Signal
.Declaration
Swift
public init()
-
Emits
self
to all subscribers.Declaration
Swift
public func emit(_ event: Event)
-
Subscribes an object to
self
.The subscription will be automatically cancelled when the owner is deallocated. The action will be delivered asynchronously on the specified queue.
Declaration
Swift
public func subscribe(owner: AnyObject, in queue: DispatchQueue = default, action: @escaping (Event) -> Void)
Parameters
owner
subscription owner.
queue
DispatchQueue
to use when invoking the action, defaults to the main queue.action
closure to invoke when the signal is emitted.
-
Unsubscribes an object from
self
.Declaration
Swift
public func unsubscribe(_ owner: AnyObject)
Parameters
owner
subscription owner.
-
Removes all subscribers.
Declaration
Swift
public func unsubscribeAll()
-
Creates a new signal that filters events from this signal.
Declaration
Swift
public func filter(where eval: @escaping (Event) -> Bool) -> Signal<Event>
-
Returns a new signal that emits mapped event.
Declaration
Swift
public func map<T>(_ f: @escaping (Event) -> T) -> Signal<T>
-
Returns a new signal that emits mapped events and skips
nil
events.Declaration
Swift
public func flatMap<T>(_ f: @escaping (Event) -> T?) -> Signal<T>