UAAction Class Reference
Inherits from | NSObject |
Declared in | UAAction.h |
Overview
Base class for actions, which define a modular unit of work.
A block defining a monadic lift operation on the predicate block
Tasks
Other Methods
-
– acceptsArguments:
-
– willPerformWithArguments:
-
– didPerformWithArguments:withResult:
-
– performWithArguments:actionName:completionHandler:
-
– performWithArguments:completionHandler:
-
+ actionWithBlock:
-
+ actionWithBlock:acceptingArguments:
Operators Methods
Class Methods
actionWithBlock:
Factory method for creating anonymous actions
+ (instancetype)actionWithBlock:(UAActionBlock)actionBlock
Parameters
- actionBlock
A UAActionBlock representing the primary work performed by the action.
Declared In
UAAction.h
actionWithBlock:acceptingArguments:
Factory method for creating anonymous actions
+ (instancetype)actionWithBlock:(UAActionBlock)actionBlock acceptingArguments:(nullable UAActionPredicate)predicateBlock
Parameters
- actionBlock
A UAActionBlock representing the primary work performed by the action.
- predicateBlock
A UAActionPredicate limiting the scope of the arguments.
Declared In
UAAction.h
Instance Methods
acceptsArguments:
Called before an action is performed to determine if the the action can accept the arguments.
- (BOOL)acceptsArguments:(UAActionArguments *)arguments
Parameters
- arguments
A UAActionArguments value representing the arguments passed to the action.
Return Value
YES if the action can perform with the arguments, otherwise NO
Discussion
This method can be used both to verify that an argument’s value is an appropriate type, as well as to limit the scope of execution of a desired range of values. Rejecting arguments will result in the action not being performed when it is run.
Declared In
UAAction.h
bind:
Operator for creating a monadic binding.
- (UAAction *)bind:(UAActionBindBlock)bindBlock
Parameters
- bindBlock
A UAActionBindBlock
Return Value
A new UAAction wrapping the receiver and binding the passed block.
Declared In
UAAction+Operators.h
continueWith:
Operator for chaining two actions together in sequence.
- (UAAction *)continueWith:(UAAction *)continuationAction
Parameters
- continuationAction
A UAAction to be executed as the continuation of the receiver.
Return Value
A new UAAction wrapping the receiver and the continuationAction, which chains the two together when run.
Discussion
When run, if the receiver executes normally, the result will be passed in the arguments to the supplied continuation action, whose result will be passed in the completion handler as the final result.
Otherwise if the receiver action rejects its arguments or encounters an error, the continuation will finish early and the receiver’s result will be passed in the completion handler.
The result of the aggregate action is the result of the second action.
Declared In
UAAction+Operators.h
didPerformWithArguments:withResult:
Called after the action has performed, before its final completion handler is called.
- (void)didPerformWithArguments:(UAActionArguments *)arguments withResult:(UAActionResult *)result
Parameters
- arguments
A UAActionArguments value representing the arguments passed to the action.
- result
A UAActionResult from performing the action.
Discussion
This method can be used to define optional teardown or post-execution logic.
Declared In
UAAction.h
filter:
Operator for limiting the scope of an action with a predicate block.
- (UAAction *)filter:(UAActionPredicate)filterBlock
Parameters
- filterBlock
A UAActionPredicate block.
Return Value
A new UAAction wrapping the receiver and applying the supplied filterBlock to its argument validation logic.
Discussion
This operator serves the same purpose as the [UAAction acceptsArguments:] method, but can be used to customize an action ad-hoc without deriving a subclass.
Declared In
UAAction+Operators.h
lift:
Operator for lifting a block transforming an action block, into a monadic binding.
- (UAAction *)lift:(UAActionLiftBlock)liftBlock
Parameters
- liftBlock
A UAActionLiftBlock
Return Value
A new UAAction wrapping the receiver, which lifts the passed block into a bind operation.
Declared In
UAAction+Operators.h
lift:transformingPredicate:
Operator for lifting a block transforming an action block and predicate, into a monadic binding.
- (UAAction *)lift:(UAActionLiftBlock)actionLiftBlock transformingPredicate:(UAActionPredicateLiftBlock)predicateLiftBlock
Parameters
- actionLiftBlock
A UAActionLiftBlock
- predicateLiftBlock
A UAActionPredicteLiftBlock
Return Value
A new UAAction wrapping the receiver, which lifts the passed blocks into a bind operation.
Declared In
UAAction+Operators.h
map:
Operator for transforming the arguments passed into an action.
- (UAAction *)map:(UAActionMapArgumentsBlock)mapArgumentsBlock
Parameters
- mapArgumentsBlock
A UAActionMapArgumentsBlock
Return Value
A new UAAction wrapping the receiver and applying the supplied mapArgumentsBlock as a transformation on the arguments.
Declared In
UAAction+Operators.h
performWithArguments:actionName:completionHandler:
Performs the action.
- (void)performWithArguments:(UAActionArguments *)arguments actionName:(NSString *)name completionHandler:(UAActionCompletionHandler)completionHandler
Parameters
- arguments
A UAActionArguments value representing the arguments passed to the action.
- name
A NSString representing the name of the action.
- completionHandler
A UAActionCompletionHandler that will be called when the action has finished executing.
Discussion
Subclasses of UAAction should override this method to define custom behavior.
Note: You should not ordinarily call this method directly. Instead, use the UAActionRunner
.
Declared In
UAAction.h
performWithArguments:completionHandler:
Performs the action.
- (void)performWithArguments:(UAActionArguments *)arguments completionHandler:(UAActionCompletionHandler)completionHandler
Parameters
- arguments
A UAActionArguments value representing the arguments passed to the action.
- completionHandler
A UAActionCompletionHandler that will be called when the action has finished executing.
Discussion
Subclasses of UAAction should override this method to define custom behavior.
Note: You should not ordinarily call this method directly. Instead, use the UAActionRunner
.
Declared In
UAAction.h
postExecution:
Operator for adding additional post-execution logic to an action.
- (UAAction *)postExecution:(UAActionPostExecutionBlock)postExecutionBlock
Parameters
- postExecutionBlock
A UAActionPostExecutionBlock.
Return Value
A new UAAction wrapping the receiver that executes the postExecutionBlock when run, before performing.
Discussion
This operator serves the same purpose as [UAAction didPerformWithArguments:withResult:] but can be used to customize an action ad-hoc without deriving a subclass.
Declared In
UAAction+Operators.h
preExecution:
Operator for adding additional pre-execution logic to an action.
- (UAAction *)preExecution:(UAActionPreExecutionBlock)preExecutionBlock
Parameters
- preExecutionBlock
A UAActionPreExecutionBlock.
Return Value
A new UAAction wrapping the receiver that executes the preExecutionBlock when run, before performing.
Discussion
This operator serves the same purpose as [UAAction willPerformWithArguments:] but can be used to customize an action ad-hoc without deriving a subclass.
Declared In
UAAction+Operators.h
willPerformWithArguments:
Called before the action’s performWithArguments:withCompletionHandler:
- (void)willPerformWithArguments:(UAActionArguments *)arguments
Parameters
- arguments
A UAActionArguments value representing the arguments passed to the action.
Discussion
This method can be used to define optional setup or pre-execution logic.
Declared In
UAAction.h