Skip to content

Instantly share code, notes, and snippets.

@roparz
Last active August 29, 2015 14:04
Show Gist options
  • Save roparz/d3ae1bc84466025e3dcc to your computer and use it in GitHub Desktop.
Save roparz/d3ae1bc84466025e3dcc to your computer and use it in GitHub Desktop.
AngularJS route builder that avoid declaration duplication
_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