Signal type.
State type.
The resulting state of a transition or a function returning one.
A list of transitions.
This signal fires if the target React component catches error
This signal fires when the target React component is created.
Initial state of Automaton
This signal fires after the target React component is mounted.
This signal fires before the target React component is unmounted.
This signal fires after the target React component is updated.
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:
componentDidMount
componentDidUpdate
componentWillUnmount
componentDidCatch
and if catching
parameter is set to true:import {withAutomaton} from 'automatons';
@withAutomaton({catching: true})
class Button extends React.Component
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.
target React component
desired signal
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';
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')}/>
);
}
}
target component
Creates a SideEffect that is an empty transition returning the previous state.
target state
side effect function
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'
state that makes the transition possible and starts the timer
timeout in milliseconds
transition function
This function constructs a desired Transition from provided State, Signal and implementation.
If no signal provided, this function constructs an unconditional transition, which is triggered by any signal.
Generated using TypeDoc
Side effect implementation function.