BehaviorRunner
A thin wrapper around the execution of a behaviors actions in order to support behavior pausing.
A behavior is in a paused state when the property $WBBehaviorPaused
,
found on the window
object, is truthy and when that property is
falsy the behavior is considered in an un-paused state.
The check for a behavior pause state transitions is done before performing the behaviors next action, allowing the action to be atomic.
Constructor Summary
Public Constructor | ||
public |
constructor(init: BehaviorRunnerOpts) |
Member Summary
Public Members | ||
public get |
Returns T/F indicating if the behavior is currently paused |
|
public |
|
|
public |
A function used to transform the return value of BehaviorRunner#stepIterator after performing an action into a value that is interpretable by Webrecorders automation system. |
|
public |
The behavior's action iterator |
|
public |
|
Private Members | ||
private |
|
Method Summary
Public Methods | ||
public |
Shortcut for running a behavior from a for await of loop. |
|
public |
async autoRun(options: BehaviorRunOptions): Promise<void> Automatically run the behavior |
|
public |
async * autoRunIter(delayAmount: number): AsyncIterableIterator<BehaviorStepResults> Shortcut for automatically run the behavior via async generators |
|
public |
async autoRunWithDelay(options: BehaviorRunOptions): Promise<void> Automatically run the behavior to completion optionally supplying an amount of time, in milliseconds, that will be waited for before initiating another action the wait after performing an behavior action (step) |
|
public |
pause() Pauses the behavior by setting the behavior paused flag to true |
|
public |
Calls the next function of BehaviorRunner#stepIterator and if a postStepFN was supplied it is called with the results of the performed action otherwise they are returned directly. |
|
public |
Initiates the next action of a behavior. |
|
public |
swapBehaviorIterator(newBehaviorIterator: RawBehaviorIterator, newPostStepFN: function(results: RawBehaviorStepResults): BehaviorStepResults) Swaps the behavior actions to be applied to the page. |
|
public |
swapPostStepFn(newPostStepFN: function(results: RawBehaviorStepResults): BehaviorStepResults) Swaps the postStepFN to be used. |
|
public |
unpause() Un-pauses the behavior by setting the behavior paused flag to false |
|
public |
waitToBeUnpaused(): Promise<void> Returns a promise that resolves once |
Public Constructors
public constructor(init: BehaviorRunnerOpts) source
Params:
Name | Type | Attribute | Description |
init | BehaviorRunnerOpts |
Public Members
public postStepFN: function(result: RawBehaviorStepResults): BehaviorStepResults source
A function used to transform the return value of BehaviorRunner#stepIterator after performing an action into a value that is interpretable by Webrecorders automation system.
Private Members
Public Methods
public [Symbol.asyncIterator](): BehaviorRunnerAsyncIterator source
Shortcut for running a behavior from a for await of loop.
public async autoRun(options: BehaviorRunOptions): Promise<void> source
Automatically run the behavior
Params:
Name | Type | Attribute | Description |
options | BehaviorRunOptions |
|
public async * autoRunIter(delayAmount: number): AsyncIterableIterator<BehaviorStepResults> source
Shortcut for automatically run the behavior via async generators
Params:
Name | Type | Attribute | Description |
delayAmount | number |
|
Optional amount of delay to be applied between steps |
Example:
// in some async function
for await (const value of runner.autoRunIter()) {
console.log(value)
}
public async autoRunWithDelay(options: BehaviorRunOptions): Promise<void> source
Automatically run the behavior to completion optionally supplying an amount of time, in milliseconds, that will be waited for before initiating another action the wait after performing an behavior action (step)
Params:
Name | Type | Attribute | Description |
options | BehaviorRunOptions |
|
public performStep(): Promise<BehaviorStepResults> source
Calls the next function of BehaviorRunner#stepIterator and if a postStepFN was supplied it is called with the results of the performed action otherwise they are returned directly.
public step(): Promise<BehaviorStepResults> source
Initiates the next action of a behavior.
If the behavior is transitioning into the paused state (previously not paused) the promise returned resolves with the results of performing the next action once the un-paused state has been reached.
If this method is called and the behavior is currently in the paused state the promise returned is the same one returned when transitioning into the paused state.
Otherwise the returned promise resolves with the state of the behavior after performing an action.
public swapBehaviorIterator(newBehaviorIterator: RawBehaviorIterator, newPostStepFN: function(results: RawBehaviorStepResults): BehaviorStepResults) source
Swaps the behavior actions to be applied to the page.
Params:
Name | Type | Attribute | Description |
newBehaviorIterator | RawBehaviorIterator | a new behavior action iterator to be run |
|
newPostStepFN | function(results: RawBehaviorStepResults): BehaviorStepResults |
|
an optional new post step function to be used. If a previous postStepFN is in use and a new function is not supplied the old one is persisted. |
public swapPostStepFn(newPostStepFN: function(results: RawBehaviorStepResults): BehaviorStepResults) source
Swaps the postStepFN to be used.
Params:
Name | Type | Attribute | Description |
newPostStepFN | function(results: RawBehaviorStepResults): BehaviorStepResults | The new postStepFN to be used. |