SignalType
public protocol SignalType : AnyObject
Base protocol for signals, which deliver values produced by some source and notify observers when a change is being made.
-
The type of values that are delivered on this signal.
Declaration
Swift
associatedtype Value -
Adds the given observer to the set of observers that are notified when this signal’s value has changed. If the given observer is the first one to be added for this signal, the underlying signal source will be brought to action. If the signal source has a value available, the given observer will be sent a
valueChangingevent beforeobservereturns.Declaration
Swift
func addObserver(_ observer: SignalObserver<Value>) -> ObserverRemoval -
property()Default implementationLifts this signal into an AsyncReadableProperty.
Default Implementation
Lifts this signal into an AsyncReadableProperty.
Declaration
Swift
func property() -> AsyncReadableProperty<Value> -
Returns the number of attached observers. For testing purposes only.
Declaration
Swift
var observerCount: Int { get }
-
property(mutator:)Extension methodLifts this signal into an AsyncReadWriteProperty that writes values back to a relation via the given mutator.
Declaration
Swift
public func property(mutator: RelationMutationConfig<Value>) -> AsyncReadWriteProperty<Value>
-
observe(_:)Extension methodConvenience form of observe that takes an event handler function.
Declaration
Swift
public func observe(_ onEvent: @escaping (SignalEvent<Value>) -> Void) -> ObserverRemoval -
observeValueChanging(_:)Extension methodConvenience form of observe that only responds to
valueChangingevents. Any other events are treated as no-ops.Declaration
Swift
public func observeValueChanging(_ onValueChanging: @escaping (Value, ChangeMetadata) -> Void) -> ObserverRemoval -
observeSynchronousValueChanging(_:)Extension methodConvenience form of observe that only accepts
valueChangingevents. Any other events are considered a fatal error. This is mainly useful in cases where the observed signal is expected to be fully synchronous, i.e., always delivers changes immediately.Declaration
Swift
public func observeSynchronousValueChanging(_ onValueChanging: @escaping (Value, ChangeMetadata) -> Void) -> ObserverRemoval
-
map(_:)Extension method -
flatMap(_:)Extension methodReturns a Signal whose values are derived from the given signal. The given
transformwill be applied whenever this signal’s value changes, and in turn the signal returned bytransformbecomes the new source of values.
SignalType Protocol Reference