Skip to content

Instantly share code, notes, and snippets.

@dcneiner
Created December 20, 2012 17:58
Show Gist options
  • Save dcneiner/4347257 to your computer and use it in GitHub Desktop.
Save dcneiner/4347257 to your computer and use it in GitHub Desktop.
An example state machine that also maintains css state.
var Lightswitch = machina.Fsm.extend({
initialState: "off",
states: {
off: {
},
on: {
}
}
});
var LightswitchView = Backbone.View.extend({
initialize: function () {
this.fsm = new Lightswitch();
var self = this;
this.fsm.on( "transition", function ( data ){
if ( data.fromState ) {
self.$el.removeClass( "is-" + data.fromState );
}
if ( data.toState ) {
self.$el.addClass( "is-" + data.toState );
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment