Action

public final class Action<Input, Output, Error: Swift.Error>

Represents an action that will do some work when executed with a value of type Input, then return zero or more values of type Output and/or fail with an error of type Error. If no failure should be possible, NoError can be specified for the Error parameter.

Actions enforce serial execution. Any attempt to execute an action multiple times concurrently will return an error.

  • The lifetime of the Action.

    Declaration

    Swift

    public let lifetime: Lifetime
  • A signal of all events generated from applications of the Action.

    In other words, this will send every Event from every signal generated by each SignalProducer returned from apply() except ActionError.disabled.

    Declaration

    Swift

    public let events: Signal<Event<Output, Error>, NoError>
  • A signal of all values generated from applications of the Action.

    In other words, this will send every value from every signal generated by each SignalProducer returned from apply() except ActionError.disabled.

    Declaration

    Swift

    public let values: Signal<Output, NoError>
  • A signal of all errors generated from applications of the Action.

    In other words, this will send errors from every signal generated by each SignalProducer returned from apply() except ActionError.disabled.

    Declaration

    Swift

    public let errors: Signal<Error, NoError>
  • A signal which is triggered by ActionError.disabled.

    Declaration

    Swift

    public let disabledErrors: Signal<(), NoError>
  • A signal of all completed events generated from applications of the action.

    In other words, this will send completed events from every signal generated by each SignalProducer returned from apply().

    Declaration

    Swift

    public let completed: Signal<(), NoError>
  • Whether the action is currently executing.

    Declaration

    Swift

    public let isExecuting: Property<Bool>
  • Whether the action is currently enabled.

    Declaration

    Swift

    public let isEnabled: Property<Bool>
  • Initializes an action that will be conditionally enabled based on the value of state. Creates a SignalProducer for each input and the current value of state.

    Note

    Action guarantees that changes to state are observed in a thread-safe way. Thus, the value passed to isEnabled will always be identical to the value passed to execute, for each application of the action.

    Note

    This initializer should only be used if you need to provide custom input can also influence whether the action is enabled. The various convenience initializers should cover most use cases.

    Declaration

    Swift

    public init<State: PropertyProtocol>(state property: State, enabledIf isEnabled: @escaping (State.Value) -> Bool, _ execute: @escaping (State.Value, Input) -> SignalProducer<Output, Error>)

    Parameters

    state

    A property that provides the current state of the action whenever apply() is called.

    enabledIf

    A predicate that, given the current value of state, returns whether the action should be enabled.

    execute

    A closure that returns the SignalProducer returned by calling apply(Input) on the action, optionally using the current value of state.

  • Initializes an action that will be conditionally enabled, and creates a SignalProducer for each input.

    Declaration

    Swift

    public convenience init<P: PropertyProtocol>(enabledIf property: P, _ execute: @escaping (Input) -> SignalProducer<Output, Error>) where P.Value == Bool

    Parameters

    enabledIf

    Boolean property that shows whether the action is enabled.

    execute

    A closure that returns the signal producer returned by calling apply(Input) on the action.

  • Initializes an action that will be enabled by default, and creates a SignalProducer for each input.

    Declaration

    Swift

    public convenience init(_ execute: @escaping (Input) -> SignalProducer<Output, Error>)

    Parameters

    execute

    A closure that returns the signal producer returned by calling apply(Input) on the action.

  • Creates a SignalProducer that, when started, will execute the action with the given input, then forward the results upon the produced Signal.

    Note

    If the action is disabled when the returned SignalProducer is started, the produced signal will send ActionError.disabled, and nothing will be sent upon values or errors for that particular signal.

    Declaration

    Swift

    public func apply(_ input: Input) -> SignalProducer<Output, ActionError<Error>>

    Parameters

    input

    A value that will be passed to the closure creating the signal producer.

  • Initializes an action that uses an Optional property for its input, and is disabled whenever the input is nil. When executed, a SignalProducer is created with the current value of the input.

    Declaration

    Swift

    public convenience init<P: PropertyProtocol, T>(input: P, _ execute: @escaping (T) -> SignalProducer<Output, Error>) where P.Value == T?

    Parameters

    input

    An Optional property whose current value is used as input whenever the action is executed. The action is disabled whenever the value is nil.

    execute

    A closure to return a new SignalProducer based on the current value of input.

  • Initializes an action that uses a property for its input. When executed, a SignalProducer is created with the current value of the input.

    Declaration

    Swift

    public convenience init<P: PropertyProtocol, T>(input: P, _ execute: @escaping (T) -> SignalProducer<Output, Error>) where P.Value == T

    Parameters

    input

    A property whose current value is used as input whenever the action is executed.

    execute

    A closure to return a new SignalProducer based on the current value of input.