Home Reference Source
import {BehaviorRunner} from 'lib/behaviorRunner.js'
public class | source

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

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

_waitP: Promise<void>

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

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

Swaps the behavior actions to be applied to the page.

public

Swaps the postStepFN to be used.

public

Un-pauses the behavior by setting the behavior paused flag to false

public

Returns a promise that resolves once window.$WBBehaviorPaused is falsy, checking at 2 second intervals.

Public Constructors

public constructor(init: BehaviorRunnerOpts) source

Params:

NameTypeAttributeDescription
init BehaviorRunnerOpts

Public Members

public get isPaused: boolean: * source

Returns T/F indicating if the behavior is currently paused

Return:

boolean

public metadata: Object source

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.

public stepIterator: RawBehaviorIterator source

The behavior's action iterator

public upCheckInterval: number source

Private Members

private _waitP: Promise<void> source

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:

NameTypeAttributeDescription
options BehaviorRunOptions
  • optional
  • default: {}

Return:

Promise<void>

public async * autoRunIter(delayAmount: number): AsyncIterableIterator<BehaviorStepResults> source

Shortcut for automatically run the behavior via async generators

Params:

NameTypeAttributeDescription
delayAmount number
  • optional

Optional amount of delay to be applied between steps

Return:

AsyncIterableIterator<BehaviorStepResults>

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:

NameTypeAttributeDescription
options BehaviorRunOptions
  • optional
  • default: {}

Return:

Promise<void>

public pause() source

Pauses the behavior by setting the behavior paused flag to true

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:

NameTypeAttributeDescription
newBehaviorIterator RawBehaviorIterator

a new behavior action iterator to be run

newPostStepFN function(results: RawBehaviorStepResults): BehaviorStepResults
  • optional

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:

NameTypeAttributeDescription
newPostStepFN function(results: RawBehaviorStepResults): BehaviorStepResults

The new postStepFN to be used.

public unpause() source

Un-pauses the behavior by setting the behavior paused flag to false

public waitToBeUnpaused(): Promise<void> source

Returns a promise that resolves once window.$WBBehaviorPaused is falsy, checking at 2 second intervals.

Return:

Promise<void>