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
  • Converts this instance into a concrete Signal.

    Declaration

    Swift

    var signal: Signal<Value> { get }
  • 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 valueChanging event before observe returns.

    Declaration

    Swift

    func addObserver(_ observer: SignalObserver<Value>) -> ObserverRemoval
  • property() Default implementation

    Lifts 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 }
  • observe(_:) Extension method

    Convenience form of observe that takes an event handler function.

    Declaration

    Swift

    public func observe(_ onEvent: @escaping (SignalEvent<Value>) -> Void) -> ObserverRemoval
  • observeValueChanging(_:) Extension method

    Convenience form of observe that only responds to valueChanging events. Any other events are treated as no-ops.

    Declaration

    Swift

    public func observeValueChanging(_ onValueChanging: @escaping (Value, ChangeMetadata) -> Void) -> ObserverRemoval
  • Convenience form of observe that only accepts valueChanging events. 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

    Returns a Signal that applies the given transform to each new value.

    Declaration

    Swift

    public func map<U>(_ transform: @escaping (Self.Value) -> U) -> Signal<U>
  • flatMap(_:) Extension method

    Returns a Signal whose values are derived from the given signal. The given transform will be applied whenever this signal’s value changes, and in turn the signal returned by transform becomes the new source of values.

    Declaration

    Swift

    public func flatMap<S: SignalType>(_ transform: @escaping (Self.Value) -> S) -> Signal<S.Value>
  • or(_:) Extension method

    Returns a Signal whose value resolves to the logical OR of the values delivered on this signal and the other input signal.

    Declaration

    Swift

    public func or<S>(_ other: S) -> Signal<Bool> where S : SignalType, S.Value == Bool
  • and(_:) Extension method

    Returns a Signal whose value resolves to the logical AND of the values delivered on this signal and the other input signal.

    Declaration

    Swift

    public func and<S>(_ other: S) -> Signal<Bool> where S : SignalType, S.Value == Bool
  • then(_:) Extension method

    Returns a Signal that invokes the given function whenever this signal’s value resolves to true.

    Declaration

    Swift

    public func then(_ f: @escaping () -> Void) -> Signal<()>