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

State machine events should be Backbone events #1

Closed sebpiq closed 12 years ago

sebpiq commented 12 years ago

Right now there is separation between state machine events and backbone events (e.g. triggering a state machine event with 'receive') ... there shouldn't be.

sebpiq commented 12 years ago

for example this could simplify the following case :

    MyView = StatefulView.extend({
        events: {'click': 'clickedCallback'},

        states: {idle: {}, focused: {}},
        transitions: {
            idle: {focus: {enterState: 'focused'}},
            focused: {blur: {enterState: 'idle'}}
        },
        currentState: 'idle',

        clickedCallback: function() {
            this.receive('focus');
        }
    });

Where the sole purpose of the callback is to trigger a state-machine event when click event received. Cool thing would be :

    MyView = StatefulView.extend({

        states: {idle: {}, focused: {}},
        transitions: {
            idle: {click: {enterState: 'focused'}},
            focused: {blur: {enterState: 'idle'}}
        },
        currentState: 'idle',

    });
sebpiq commented 12 years ago

Events could also be event selectors as in Backbone.Events :

    MyView = StatefulView.extend({

        states: {idle: {}, focused: {}},
        transitions: {
            idle: {'click .aSpecialDiv': {enterState: 'focused'}},
            focused: {blur: {enterState: 'idle'}}
        },
        currentState: 'idle',

    });
sebpiq commented 12 years ago

all fixed