Skip to content

ContainsΒ #19

@theKashey

Description

@theKashey
  • contains(name, MachineDef, [states], [conditions]) to define submachines
  • on('@attach') event, triggered on machine creation
  • on('@detach') event, triggered on machine destruction
  • .children[name] to access child machines
  • contains(name) to check containtent existance.
  • signalFrom(nameMachine, event, [states]) - to respont to signals.
const clockMachine = faste()
 .on('@init',({setState, attrs, trigger}) => setState({ 
    interval: setInterval(() => emit('next'), attrs.duration)
 }))
 .on('@destroy', ({state}) => clearInterval(state.interval));

const light = faste()
  // simple machine
  .contains('clock', clockMachine)
  // with dynamic constructor
  .contains('clock', ({attrs}) => ({faste: clockMachine, attrs: { duration: attrs.duration || 10}})))

  .signalFrom('clock', 'tick', ({emit}) => trigger('switch'))

  .on('tick',['on'], ({transitTo}) => transitTo('off'))
  .on('tick',['off'], ({transitTo}) => transitTo('on'))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions