lundi 21 décembre 2015

In an Ember route how can I check if an action exists?

In a component it is really easy to have an optional action provided to the component. In the JS of the component I can write:

if (this.get('someAction')) {
  this.sendAction('someAction');
}

In my application route I have a 'generic action' that saves me providing widget components with long lists of actions, it looks like this:

genericAction: function(customActionName, customActionParams) {
  this.send(customActionName, customActionParams);
}

For various reasons (including using genericAction in some components to fire an action a test could subscribe to, but the app not necessarily use in some hard to test async/pretender workflows) I would prefer to check the action exists, i.e:

genericAction: function(customActionName, customActionParams) {
  if (this.get(customActionName)) {
    this.send(customActionName, customActionParams);
  }
}

Similar to how you can in a component, however this does not work, nor does this.controller.get(customActionName).

Other than keeping a hard coded list of actions, how can I achieve this?




Aucun commentaire:

Enregistrer un commentaire