Created
December 20, 2012 17:58
-
-
Save dcneiner/4347257 to your computer and use it in GitHub Desktop.
An example state machine that also maintains css state.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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