YahooArchive/dispatchr

Handler definitions as functions to promote a sort of Revealing Module Pattern

Closed this issue · 0 comments

Currently Stores look like the following:

module.exports = createStore({
    statics: {
        storeName: 'SomeStore',
        handlers: {
            'SOME_MUTATION': 'some_mutation',
        }
    },

    some_mutation: function(state) {
        this.state.count++;
        this.emitChage();
    },

    initialize: function() {
        ...
    },

    getState: function() {
        return this.state;
    }
});

The problem here is that the store "mutation" functions are still accessible, a way that would help hide direct mutation calls would be to allow the "handlers" hash to accept functions instead of just method name strings

example:

module.exports = createStore({
    statics: {
        storeName: 'SomeStore',
        handlers: {
            'SOME_MUTATION': function(state) {
                this.state.count++;
                this.emitChage();
            }
        }
    },

    initialize: function() {
        ...
    },

    getState: function() {
        return this.state;
    }
});

This limits mutations to not be directly accessible on the store object, but only thought the action handlers, of course the store would be bound to "this" in the handler functions.

This would help separate accessor and mutator functions in stores.