Last active
August 29, 2015 13:57
-
-
Save workmanw/9547230 to your computer and use it in GitHub Desktop.
Controller Actions opinion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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. // |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Discourse seems to take Option1 in some cases and Option2 in others: https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/controllers/composer_controller.js#L23-L49