Skip to content

Instantly share code, notes, and snippets.

@jrencz
Created January 21, 2016 10:43
Show Gist options
  • Save jrencz/08b491c51c2f323fe4ae to your computer and use it in GitHub Desktop.
Save jrencz/08b491c51c2f323fe4ae to your computer and use it in GitHub Desktop.
An idea of shorter syntax for loading services in angular1
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