-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
99 additions
and
94 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/* exported Injector */ | ||
function Injector() { | ||
this.types = {}; | ||
this.providers = {}; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,60 @@ | ||
var lifetimes = ['singleton', 'transient', 'root', 'parent', 'state'], | ||
injector; | ||
|
||
var old_injector = window.injector; | ||
|
||
/*---------------------- | ||
-- Injection Methods -- | ||
----------------------*/ | ||
function _inject (name, parent) { | ||
var descriptor, type, dependency_providers; | ||
if (typeof name === 'string') { | ||
descriptor = this.fakes[name] || this.types[name] || this.providers[name]; | ||
if (this.cache[name] && this.cache[name].hashCode === descriptor.hashCode) { | ||
return this.cache[name]; | ||
} | ||
|
||
} else { | ||
descriptor = this.build_anonymous_descriptor(name); | ||
/* globals Injector: false */ | ||
/* globals window: false */ | ||
/* exported lifetimes */ | ||
/* exported old_injector */ | ||
var lifetimes = ['singleton', 'transient', 'root', 'parent', 'state']; | ||
|
||
var old_injector = window.injector; | ||
|
||
/*---------------------- | ||
-- Injection Methods -- | ||
----------------------*/ | ||
function _inject (name, parent) { | ||
var descriptor, dependency_providers; | ||
if (typeof name === 'string') { | ||
descriptor = this.fakes[name] || this.types[name] || this.providers[name]; | ||
if (this.cache[name] && this.cache[name].hashCode === descriptor.hashCode) { | ||
return this.cache[name]; | ||
} | ||
|
||
if (!descriptor) { | ||
if (parent) { | ||
return null; | ||
} else { | ||
throw 'There is no dependency named "' + name + '" registered.'; | ||
} | ||
} | ||
if (descriptor.provider && descriptor.provider !== parent) { | ||
return _inject.call(this, descriptor.provider, name); | ||
} | ||
|
||
type = descriptor.type; | ||
|
||
dependency_providers = {}; | ||
_.each(descriptor.dependencies, function (dependency_name) { | ||
dependency_providers[dependency_name] = _inject.call(this, dependency_name, name); | ||
}, this); | ||
} else { | ||
descriptor = this.build_anonymous_descriptor(name); | ||
} | ||
|
||
return this.build_provider(name, descriptor, dependency_providers); | ||
if (!descriptor) { | ||
if (parent) { | ||
return null; | ||
} else { | ||
throw 'There is no dependency named "' + name + '" registered.'; | ||
} | ||
} | ||
if (descriptor.provider && descriptor.provider !== parent) { | ||
return _inject.call(this, descriptor.provider, name); | ||
} | ||
|
||
Injector.prototype.inject = function (name) { | ||
return _inject.call(this, name); | ||
}; | ||
dependency_providers = {}; | ||
_.each(descriptor.dependencies, function (dependency_name) { | ||
dependency_providers[dependency_name] = _inject.call(this, dependency_name, name); | ||
}, this); | ||
|
||
Injector.prototype.get = function (name, context, adhoc_dependencies) { | ||
var provider = this.inject(name); | ||
if (context) { | ||
return provider.call(context, adhoc_dependencies); | ||
} | ||
return provider(adhoc_dependencies); | ||
}; | ||
return this.build_provider(name, descriptor, dependency_providers); | ||
} | ||
|
||
Injector.prototype.run = function (context, adhoc_dependencies) { | ||
if (!this.providers.main) { | ||
throw 'No main method registered. Please register one by running injector.registerMain() before running the app'; | ||
} | ||
return this.get('main', context, adhoc_dependencies); | ||
}; | ||
Injector.prototype.inject = function (name) { | ||
return _inject.call(this, name); | ||
}; | ||
|
||
Injector.prototype.get = function (name, context, adhoc_dependencies) { | ||
var provider = this.inject(name); | ||
if (context) { | ||
return provider.call(context, adhoc_dependencies); | ||
} | ||
return provider(adhoc_dependencies); | ||
}; | ||
|
||
Injector.prototype.run = function (context, adhoc_dependencies) { | ||
if (!this.providers.main) { | ||
throw 'No main method registered. Please register one by running injector.registerMain() before running the app'; | ||
} | ||
return this.get('main', context, adhoc_dependencies); | ||
}; |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/** | ||
* Created by nico on 17/03/2015. | ||
*/ | ||
/* globals requirejs: false */ | ||
requirejs.config({ | ||
shim: { | ||
'lodash': { | ||
|