AngularJS service to implement a simple finite state machine.