princess
v0.0.1
Published
Tiny scoped dependency injector.
Downloads
3
Readme
Modules
module.exports : Scope ⏏
Kind: Exported member
Scope
A dependency injection scope.
Kind: global interface
scope.run(deps, fn) ⇒ *
Run a function using dependencies.
Kind: instance method of Scope
Returns: * - the return value of the provided function
| Param | Type | Description | | --- | --- | --- | | deps | Array.<string> | dependencies of this function | | fn | function | a function to invoke with that dependency |
scope.get(name) ⇒ *
Look up a dependency from this scope.
Kind: instance method of Scope
Returns: * - the registered object
| Param | Type | Description | | --- | --- | --- | | name | string | name of the object to look up |
scope.scope([scopes]) ⇒ Scope
Create a new scope.
If no argument is provided, this will be a child of the current scope.
If an array of scopes is provided, this will be a child of those scopes.
An empty array can be provided to create a detached scope which inherits from no other scopes.
Kind: instance method of Scope
Returns: Scope - the new scope
| Param | Type | Description | | --- | --- | --- | | [scopes] | Array.<Scope> | parent scopes |
scope.has(name)
Check if something of this name has been registered.
Kind: instance method of Scope
| Param | Type | Description | | --- | --- | --- | | name | string | name of the registered object |
scope.register(name, deps, fn, [scope]) ⇒ Scope
Register an object in this dependency injection scope.
Kind: instance method of Scope
Returns: Scope - the current scope
| Param | Type | Description | | --- | --- | --- | | name | string | name of the object to register | | deps | Array.<string> | dependencies of the registered object | | fn | function | function which will return this object | | [scope] | Scope | scope from which to look up dependencies (if omitted, will use the same scope.) |