sebpiq / backbone.statemachine

Simple finite-state machine for Backbone. View states made easy. Synchronizing your application's parts with events made easy.
MIT License
177 stars 16 forks source link

States declaration hash should accept anonymous functions #25

Closed Fab1en closed 11 years ago

Fab1en commented 11 years ago

Callbacks are defined by function names (string) :

states: {
    visible: {enter: ['doShow'], leave: ['doHide']},
},
doShow: function() { this.el.show(); },
doHide: function() { this.el.hide(); }

Sometimes, when the callbacks are short, it's easier to use anonymous functions :

states: {
    visible: {
        enter: [function() { this.el.show(); }], 
        leave: [function() { this.el.hide(); }]
    },
}

This should be easy, but your _collectMethods prevent the use of anonymous functions. You can define anonymous function as callbacks in Vanilla Backbone events hash.

sebpiq commented 11 years ago

Merged!