Constructor
new ResourceRegistry()
Simple implementation of Registry pattern. Can store plain values or factories. Stored factory gets memoized — that is, returns same object given the same parameters. Memoizing assumes factory is pure function.
Extends
Methods
(static) processRegistry()
Iterates over context.__registry__
, acquiring dependencies from it via context.registry.acquire
.
__registry__
can be hash or array (or a function returning such hash or array).
Hash keys are keys to inject acquired resources, and values are keys to acquire. If value is array, than first element is key, second is params fo factory. Array is simplified form of hash. Following hash and array are equivalent:
{
'res1': 'res1',
factory1: ['factory1', {param: 42}]
}, // and
['res1', ['factory1', {param: 42}]]
(protected) _parentResult(cls, propertyName) → {*}
Much like a _.result
, but ascending to parent
Parameters:
Name | Type | Description |
---|---|---|
cls |
function | class derived in usual Skull paradigm (i.e. with |
propertyName |
String |
- Inherited From:
- Source:
Returns:
Most of the times it is Object
- Type
- *
acquire(key, optionsopt) → {*}
Returns requested object from registry
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
key |
String | ||
options |
Object |
<optional> |
if present, factory would be called instead of fetching plain value |
Returns:
- Type
- *
initialize(options)
Parameters:
Name | Type | Description |
---|---|---|
options |
Object |
- Overrides:
- Source:
register(key, value, optionsopt) → {Object}
Registers object or factory by given key
. Pass third argument to store factory.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
key |
String | |||
value |
Object | |||
options |
Object |
<optional> |
{} |
Throws:
TypeError when not a function passed as factory
Returns:
what was stored
- Type
- Object
unregister(key, isFactory)
Deletes value from registry
Parameters:
Name | Type | Description |
---|---|---|
key |
String | |
isFactory |
Boolean | if true, deletes factory |