Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor($injector): minor clean up
  • Loading branch information
gkalpak committed Aug 6, 2016
commit 2e0441dd23f10bbae714a30d6eda7884a1e09c2c
26 changes: 13 additions & 13 deletions src/auto/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function stringifyFn(fn) {
// Support: Chrome 50-51 only
// Creating a new string by adding `' '` at the end, to hack around some bug in Chrome v50/51
// (See https://github.com/angular/angular.js/issues/14487.)
// TODO (gkalpak): Remove workaround when Chrome v52 is released
// TODO(gkalpak): Remove workaround when Chrome v52 is released
return Function.prototype.toString.call(fn) + ' ';
}

Expand Down Expand Up @@ -649,16 +649,16 @@ function createInjector(modulesToLoad, strictDi) {
var INSTANTIATING = {},
providerSuffix = 'Provider',
path = [],
loadedModules = new HashMap([], true),
loadedModules = new HashMap(null, true),
providerCache = {
$provide: {
provider: supportObject(provider),
factory: supportObject(factory),
service: supportObject(service),
value: supportObject(value),
constant: supportObject(constant),
decorator: decorator
}
provider: supportObject(provider),
factory: supportObject(factory),
service: supportObject(service),
value: supportObject(value),
constant: supportObject(constant),
decorator: decorator
}
},
providerInjector = (providerCache.$injector =
createInternalInjector(providerCache, function(serviceName, caller) {
Expand Down Expand Up @@ -731,7 +731,9 @@ function createInjector(modulesToLoad, strictDi) {
}]);
}

function value(name, val) { return factory(name, valueFn(val), false); }
function value(name, val) {
return factory(name, valueFn(val), false);
}

function constant(name, value) {
assertNotHasOwnProperty(name, 'constant');
Expand Down Expand Up @@ -775,9 +777,7 @@ function createInjector(modulesToLoad, strictDi) {
runBlocks = runBlocks.concat(loadModules(moduleFn.requires)).concat(moduleFn._runBlocks);
runInvokeQueue(moduleFn._invokeQueue);
runInvokeQueue(moduleFn._configBlocks);
} else if (isFunction(module)) {
runBlocks.push(providerInjector.invoke(module));
} else if (isArray(module)) {
} else if (isFunction(module) || isArray(module)) {
runBlocks.push(providerInjector.invoke(module));
} else {
assertArgFn(module, 'module');
Expand Down
23 changes: 11 additions & 12 deletions test/auto/injectorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ describe('injector', function() {
it('should resolve dependency graph and instantiate all services just once', function() {
var log = [];

// s1
// / | \
// / s2 \
// / / | \ \
// /s3 < s4 > s5
// //
// s6
// ____ s1 _
// / | \
// / __ s2 __ \
// / / | \ \
// | s3 <- s4 --> s5
// | /
// s6


providers('s1', function() { log.push('s1'); return {}; }, {$inject: ['s2', 's5', 's6']});
Expand Down Expand Up @@ -287,7 +287,7 @@ describe('injector', function() {
});

// Support: Chrome 50-51 only
// TODO (gkalpak): Remove when Chrome v52 is released.
// TODO(gkalpak): Remove when Chrome v52 is released.
// it('should be able to inject fat-arrow function', function() {
// inject(($injector) => {
// expect($injector).toBeDefined();
Expand Down Expand Up @@ -327,7 +327,7 @@ describe('injector', function() {
}

// Support: Chrome 50-51 only
// TODO (gkalpak): Remove when Chrome v52 is released.
// TODO(gkalpak): Remove when Chrome v52 is released.
// it('should be able to invoke classes', function() {
// class Test {
// constructor($injector) {
Expand Down Expand Up @@ -884,7 +884,6 @@ describe('injector', function() {
var $injector = createInjectorWithValue('instance', instance);
expect($injector.invoke(function(instance) { return instance; })).toBe(instance);
});

});


Expand Down Expand Up @@ -1039,7 +1038,7 @@ describe('injector', function() {

describe('protection modes', function() {
it('should prevent provider lookup in app', function() {
var $injector = createInjector([function($provide) {
var $injector = createInjector([function($provide) {
$provide.value('name', 'angular');
}]);
expect(function() {
Expand All @@ -1049,7 +1048,7 @@ describe('injector', function() {


it('should prevent provider configuration in app', function() {
var $injector = createInjector([]);
var $injector = createInjector([]);
expect(function() {
$injector.get('$provide').value('a', 'b');
}).toThrowMinErr("$injector", "unpr", "Unknown provider: $provideProvider <- $provide");
Expand Down