christianalfoni / flux-angular

Use the FLUX architecture with Angular JS
313 stars 50 forks source link

$action and handlers #32

Closed jolafrite closed 9 years ago

jolafrite commented 9 years ago

Into stores handlers, it would be great to be able to directly access the actions key constant instead of retype the value.

For example :

var store = { handlers: function() var handlers = {}; handlers[actions.LOAD_CURRENT_USER] = 'onLoadCurrentUser'; return handlers; }, };

To make it work I changed your code line 42 :

Store.handlers = ((true === _.isFunction(spec.handlers)) ? spec.handlers() : spec.handlers);

Maybe you have a better way ?

christianalfoni commented 9 years ago

Hi @jolafrite and thanks for the input!

If I understand you correctly you could just do this:

.store('MyStore', function () {
  var store = {
    handlers: {}
  };
  store.handlers[actions.LOAD_CURRENT_USER] = 'onLoadCurrentUser';
  return store;
});

In ES6 you can actually do this:

.store('MyStore', function () {
  return = {
    handlers: {
      [actions.LOAD_CURRENT_USER]: 'onLoadCurrentUser'
    }
  };
});

Considering this I do not think it is needed. Seems okay?

jolafrite commented 9 years ago

Version 2 is so much better, i have to take a longer look at ES6 I will stick to my modification Thanks