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
Eventfrom every signal generated by each SignalProducer returned from apply() exceptActionError.disabled. -
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 aSignalProducerfor each input and the current value ofstate.Note
Actionguarantees that changes tostateare observed in a thread-safe way. Thus, the value passed toisEnabledwill always be identical to the value passed toexecute, 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
stateA property that provides the current state of the action whenever
apply()is called.enabledIfA predicate that, given the current value of
state, returns whether the action should be enabled.executeA closure that returns the
SignalProducerreturned by callingapply(Input)on the action, optionally using the current value ofstate. -
Initializes an action that will be conditionally enabled, and creates a
SignalProducerfor each input.Declaration
Swift
public convenience init<P: PropertyProtocol>(enabledIf property: P, _ execute: @escaping (Input) -> SignalProducer<Output, Error>) where P.Value == BoolParameters
enabledIfBoolean property that shows whether the action is enabled.
executeA 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
executeA 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 uponvaluesorerrorsfor that particular signal.Declaration
Swift
public func apply(_ input: Input) -> SignalProducer<Output, ActionError<Error>>Parameters
inputA value that will be passed to the closure creating the signal producer.
-
Initializes an action that uses an
Optionalproperty for its input, and is disabled whenever the input isnil. When executed, aSignalProduceris 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
inputAn
Optionalproperty whose current value is used as input whenever the action is executed. The action is disabled whenever the value isnil.executeA closure to return a new
SignalProducerbased on the current value ofinput. -
Initializes an action that uses a property for its input. When executed, a
SignalProduceris 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 == TParameters
inputA property whose current value is used as input whenever the action is executed.
executeA closure to return a new
SignalProducerbased on the current value ofinput.
View on GitHub
Install in Dash
Action Class Reference