Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Type aliases

SideEffectImplementation

SideEffectImplementation: function

Side effect implementation function.

Type declaration

    • (...args: any): void
    • Parameters

      • Rest ...args: any

      Returns void

Signal

Signal: number | string | symbol

Signal type.

State

State: number | string | symbol

State type.

TransitionFunction

TransitionFunction: State | function

The resulting state of a transition or a function returning one.

Transitions

Transitions: Transition[]

A list of transitions.

Variables

Const CATCH

CATCH: "catch" = "catch"

This signal fires if the target React component catches error

see

ReactAutomaton

see

IAutomatonDecoratorParams

Const CREATE

CREATE: "create" = "create"

This signal fires when the target React component is created.

see

ReactAutomaton

Const INITIAL

INITIAL: State = "initial"

Initial state of Automaton

Const MOUNT

MOUNT: "mount" = "mount"

This signal fires after the target React component is mounted.

see

ReactAutomaton

Const UNMOUNT

UNMOUNT: "unmount" = "unmount"

This signal fires before the target React component is unmounted.

see

ReactAutomaton

Const UPDATE

UPDATE: "update" = "update"

This signal fires after the target React component is updated.

see

ReactAutomaton

Const withAutomaton

withAutomaton: decoratorFactory = mixinDecoratorFactory<IAutomatonComponent, IAutomatonDecoratorParams>(withAutomationCallbacks)

React component decorator that enchants the provided class with an Automaton instance.

withAutomaton patches some lifecycle methods of the provided component to dispatch corresponding signals. The signals dispatched are:

  • CREATE, dispatched from the constructor
  • MOUNT, dispatched from componentDidMount
  • UPDATE, dispatched from componentDidUpdate
  • UNMOUNT, dispatched from componentWillUnmount
  • CATCH, dispatched from componentDidCatch and if catching parameter is set to true:
import {withAutomaton} from 'automatons';

@withAutomaton({catching: true})
class Button extends React.Component

Functions

asSignal

  • asSignal(component: Component, signal: Signal): React.EventHandler<any>
  • Creates an event handler callback that, on being called, dispatches a Signal on corresponding React component's Automaton

    import {withAutomaton, asSignal} from 'automatons';
    
    @withAutomaton
    class Button extends React.Component {
       render() {
           return (
               <button onClick={asSignal(this, 'click')}/>
           );
       }
    }

    Handler instances produced by this function are memoized internally to avoid unnecessary re-renders.

    Parameters

    • component: Component

      target React component

    • signal: Signal

      desired signal

    Returns React.EventHandler<any>

automaton

  • Function that constructs an Automaton from the provided transition list.

    import {automaton, transition, INITIAL} from 'automatons'
    
    const stateMachine = automaton([
       transition(INITIAL, 'ready'),
       transition('ready', 'toggle', 'showing'),
       transition('showing', 'toggle', 'ready'),
    ]);
    
    stateMachine.state === INITIAL;
    
    stateMachine.transition('any signal');
    stateMachine.state === 'ready';
    
    stateMachine.transition('toggle');
    stateMachine.state === 'showing';
    
    stateMachine.transition('toggle');
    stateMachine.state === 'ready';

    Parameters

    Returns Automaton

automatonOf

  • Returns the corresponding Automaton of the provided React component

    import {withAutomaton, automatonOf} from 'automatons';
    
    @withAutomaton
    class Button extends React.Component {
       render() {
           return (
               <button onClick={() => automatonOf(this).transition('click')}/>
           );
       }
    }

    Parameters

    • component: Component

      target component

    Returns ReactAutomaton

sideEffect

timer

  • Creates a Transition that automatically occurs in a timeout.

    import {automaton, timer, INITIAL} from 'automatons'
    
    const stateMachine = automaton([
       timer(INITIAL, 1000, 'second passed'),
    ]);
    
    stateMachine.state === INITIAL;

    As one second passes:

    stateMachine.state === 'second passed'

    Parameters

    • state: State

      state that makes the transition possible and starts the timer

    • ms: number

      timeout in milliseconds

    • implementation: TransitionFunction

      transition function

    Returns Transition

transition

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc