Last active
August 29, 2015 14:04
-
-
Save roparz/d3ae1bc84466025e3dcc to your computer and use it in GitHub Desktop.
AngularJS route builder that avoid declaration duplication
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
_build = (callback) -> | |
string = callback.toString() | |
mathes = string.match /function\s?\(([\w,\s?\$]+)\)\s?\{/ | |
arr = mathes[1].split(', ') | |
arr.push callback | |
return arr | |
# using AngularUI Router | |
angular.module('app').config ($stateProvider) -> | |
# before | |
$stateProvider.state 'app.old', | |
controller: ['$state', '$stateParams', 'MyService', ($state, $stateParams, MyService) -> | |
MyService.do() | |
] | |
# after | |
$stateProvider.state 'app', | |
controller: _build ($state, $stateParams, MyService) -> | |
MyService.do() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment