yoshuawuyts / barracks

:mountain_railway: action dispatcher for unidirectional data flows
MIT License
177 stars 22 forks source link

Object based .register() syntax #2

Closed yoshuawuyts closed 10 years ago

yoshuawuyts commented 10 years ago

Change the .register() syntax to be something like:

dispatcher.register({
  user: {
    login: function() {},
    logout: function() {}
  },
  course: {
    create: function() {},
    remove: function() {}
  }
});

So the .dispatch() syntax should become something like:

dispatcher.dispatch('user.login', {foo: 'bar'});
yoshuawuyts commented 10 years ago

Or possibly:

dispatcher.dispatch('user_login', {foo: 'bar'});
yoshuawuyts commented 10 years ago

I've settled on merging barracks() and .register():

var barracks = require('barracks');

var dispatcher = barracks({
  user: {
    login: function() {},
    logout: function() {}
  },
  course: {
    create: function() {},
    remove: function() {}
  }
});

dispatcher.dispatch('user_login', {foo: 'bar'});