Skip to content

Instantly share code, notes, and snippets.

@workmanw
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save workmanw/9547230 to your computer and use it in GitHub Desktop.
Save workmanw/9547230 to your computer and use it in GitHub Desktop.
Controller Actions opinion
/*
Option 1 is the emberist way of doing it.
But I find that it makes it harder to group code in larger controllers.
*/
BC.Controller.AssetDialog = BC.Controller.extend({
actions: {
showReference: function(reference) {
/* Open reference dialog */
}
}
});
// NOTE: MY PLAN IS TO DO THIS ^^ FOR OUR WIDGETS SINCE THEY'RE SMALLER AND OFTEN ONLY HAVE ONE ACTION, IF THAT. //
/*
Option 2 is a more verbose, you can see what arguments are expect for the action.
But overall feels like you end up looking at pointless code.
*/
BC.Controller.AssetDialog = BC.Controller.extend({
showReference: function(reference) {
/* Open reference dialog */
},
actions: {
showReference: function(reference) {
this.showReference(reference);
}
}
});
/*
Option 3 makes it more concise, but feels just like a complete by-pass of Ember.
*/
BC.Controller.AssetDialog = BC.Controller.extend({
showReference: function(reference) {
/* Open reference dialog */
},
actions: {
showReference: BC.actionAlias('showReference')
}
});
// Global Helper
BC.actionAlias = function(name) {
return function() {
this[name].apply(this, arguments);
};
};
@workmanw
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment