A simple JS finite state machine

Now I know I said I wouldn’t have an excuse to produce anymore javascript libraries for a while, but I should have known that would ensure my fate. My current project is a javascript application that supports numerous states, after trying at first to manage these using a large (then larger series) of if tests, I gave up and put together a simple finite state machine FSM to resolve the transitions.

Download fsm.zip

The download contains an example.html file, open/view this for the demo. Tested in IE 6/7, Firefox, Opera and Safari.


8 Responses to “A simple JS finite state machine”

  1. 1 Mike Grace July 13, 2010 at 10:08 pm

    Nice! Thanks! Exactly what I needed.

    • 2 Anthony Blackshaw July 13, 2010 at 10:57 pm

      Hi Mike, thanks. I actually have a more up to date version of the FSM library that passes the JSLint tests if you’d like – email me ant(at)getme(dot)co(dot)uk and I’ll send you a copy.

      • 3 Mike Grace July 14, 2010 at 6:33 am

        Sweet! Absolutely. Thanks for your response.

      • 4 Nicolas Patrick Breidinger June 9, 2011 at 12:21 am

        Good code, it helped me out a lot. I ended up rewriting some of it myself to suit my project better, but you’ve got the credit for the original JS version.

        Do you have a github account with this code up? If you do I’ll fork it and show you my changes. I stripped down your code quite a bit and added a few things for my app.


  2. 5 Roy April 24, 2011 at 11:44 am

    Very simple, very nice, very good.
    As with Mike, this is just what I need
    Thanks for sharing

  3. 6 Sukima November 11, 2012 at 4:20 am

    The link to the zip file is missing. This is very sad!

    • 7 Anthony Blackshaw November 11, 2012 at 11:27 am

      Hi Sukima,

      I’ll happily email you the latest version just send me an email at ant(at)getme(dot)co(dot)uk. I’ve been meaning to put this code up on a public repo for sometime 😦

      I visited your website and noticed you’re into creative writing – I launched a creative writing project this year and thought you might be interested http://burrst.com/

  4. 8 Bobby May 9, 2014 at 4:13 am

    Way cool! Some extremely valid points! I appreciate you penning this write-up and the rest
    of the website is also really good.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: