Skip to content

apabinc/brightscript-state-machine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

State Machine (0.2)

Inspired by jakesgordon/javascript-state-machine.

Usage

sm = StateMachine().create({
    initial: "green"
    events: {
        "warn": {
            "green": "yellow"
        }
        "panic": {
            "yellow": "red"
        }
        "calm": {
            "red": "yellow"
            "*": "*"
        }
        "clear": {
            "yellow": "green"
        }
    }
    callbacks: {
        onwarn: Function() : print "onwarn callback" : End Functionon
        beforepanic: Function() : print "onbeforepanic callback" : End Function
        onpanic: Function() : print "onpanic callback" : End Function
        onyellow: Function() : print "onyellow callback": End Function
    }
})

? sm.current ' "green"
sm.call("warn", { "argument": "value" })
? sm.current ' "yellow"
? sm.can("panic") ' true
? sm.cannot("clear") ' true
sm.call("calm")
? sm.current ' "yellow"

API

  • sm.call(eventName, arguments)
  • sm.current
  • sm.can(eventName)
  • sm.cannot(eventName)
  • sm.is(stateName)

Callbacks

TBD

Notes

"*": "*" in events conditions means, that current state won't be changed

About

State management for Roku channel

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published