Created
January 21, 2016 10:43
-
-
Save jrencz/08b491c51c2f323fe4ae to your computer and use it in GitHub Desktop.
An idea of shorter syntax for loading services in angular1
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
let $log, | |
let $q; | |
// currently: | |
beforeEach(inject(function (_$log_, _$q_) { | |
$log = _$log_; | |
$q = _$q_; | |
})); | |
// maybe: | |
beforeEach(() => { | |
// still a duplication but only 2, not 3 times | |
({$log, $q} = getServices('$log', '$q')); | |
}) | |
// and somewhere under the hood | |
const getServices = (...serviceNames) => { | |
let services; | |
inject(function ($injector) { | |
services = serviceNames.reduce((services, name) => Object.assign(services, { | |
[name]: $injector.get(name), | |
}), {}); | |
}); | |
return services; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment