Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* added "sync" version of Medic Injector : less powerful but more handy

  • Loading branch information...
commit 3c3b0914faab335c00bdbd6bbe348ef301b85c66 1 parent 81465ab
@DrBenton authored
View
12 README.md
@@ -18,6 +18,14 @@ Backbone browser-side applications, etc.
It is bundled with Unit Tests and [API documentation](http://drbenton.github.com/Medic-Injector-JS/api/).
+#### Medic Injector Sync
+
+A lighter implementation is available too, with synchronous Injections values resolutions only. It is less powerful but
+it is much more simple to use, since every operation immediately return its result instead of triggering a callback.
+
+See the "medic-injector.sync.js" file and its unit tests for more information.
+
+
## Tutorial
There are two main phases to properly use this library : a "injection mappings" setup, then a "injections points" use in your
@@ -248,11 +256,11 @@ module.exports = SubscribeForm;
## API
-See te API here : http://drbenton.github.com/Medic-Injector-JS/api/
+See the API here : http://drbenton.github.com/Medic-Injector-JS/api/
The API is generated with [JSDuck](https://github.com/senchalabs/jsduck) with the following command:
- $ jsduck --output docs/api/ medic-injector.js
+ $ jsduck --output docs/api/ medic-injector.js medic-injector.sync.js
## Running Tests
View
2  docs/api/data.js
@@ -1 +1 @@
-Docs = {"data":{"guides":[],"search":[{"fullName":"InjectionMapping","url":"#!/api/InjectionMapping","sort":1,"meta":{},"name":"InjectionMapping","icon":"icon-class"},{"fullName":"InjectionMapping.constructor","url":"#!/api/InjectionMapping-method-constructor","sort":3,"meta":{},"name":"constructor","icon":"icon-method"},{"fullName":"InjectionMapping._onAsyncResolutionInSingletonMode","url":"#!/api/InjectionMapping-method-_onAsyncResolutionInSingletonMode","sort":3,"meta":{"private":true},"name":"_onAsyncResolutionInSingletonMode","icon":"icon-method"},{"fullName":"InjectionMapping._resolveModule","url":"#!/api/InjectionMapping-method-_resolveModule","sort":3,"meta":{"private":true},"name":"_resolveModule","icon":"icon-method"},{"fullName":"InjectionMapping._resolveProvider","url":"#!/api/InjectionMapping-method-_resolveProvider","sort":3,"meta":{"private":true},"name":"_resolveProvider","icon":"icon-method"},{"fullName":"InjectionMapping._throwSealedException","url":"#!/api/InjectionMapping-method-_throwSealedException","sort":3,"meta":{"private":true},"name":"_throwSealedException","icon":"icon-method"},{"fullName":"InjectionMapping._triggerFunction","url":"#!/api/InjectionMapping-method-_triggerFunction","sort":3,"meta":{"private":true},"name":"_triggerFunction","icon":"icon-method"},{"fullName":"InjectionMapping._triggerInjectionResolutionCallback","url":"#!/api/InjectionMapping-method-_triggerInjectionResolutionCallback","sort":3,"meta":{"private":true},"name":"_triggerInjectionResolutionCallback","icon":"icon-method"},{"fullName":"InjectionMapping.asSingleton","url":"#!/api/InjectionMapping-method-asSingleton","sort":3,"meta":{},"name":"asSingleton","icon":"icon-method"},{"fullName":"InjectionMapping.isSealed","url":"#!/api/InjectionMapping-method-isSealed","sort":3,"meta":{},"name":"isSealed","icon":"icon-method"},{"fullName":"InjectionMapping.resolveInjection","url":"#!/api/InjectionMapping-method-resolveInjection","sort":3,"meta":{},"name":"resolveInjection","icon":"icon-method"},{"fullName":"InjectionMapping.seal","url":"#!/api/InjectionMapping-method-seal","sort":3,"meta":{},"name":"seal","icon":"icon-method"},{"fullName":"InjectionMapping.toModule","url":"#!/api/InjectionMapping-method-toModule","sort":3,"meta":{},"name":"toModule","icon":"icon-method"},{"fullName":"InjectionMapping.toProvider","url":"#!/api/InjectionMapping-method-toProvider","sort":3,"meta":{},"name":"toProvider","icon":"icon-method"},{"fullName":"InjectionMapping.toType","url":"#!/api/InjectionMapping-method-toType","sort":3,"meta":{},"name":"toType","icon":"icon-method"},{"fullName":"InjectionMapping.toValue","url":"#!/api/InjectionMapping-method-toValue","sort":3,"meta":{},"name":"toValue","icon":"icon-method"},{"fullName":"InjectionMapping.unseal","url":"#!/api/InjectionMapping-method-unseal","sort":3,"meta":{},"name":"unseal","icon":"icon-method"},{"fullName":"InjectionMapping.injectionName","url":"#!/api/InjectionMapping-property-injectionName","sort":3,"meta":{},"name":"injectionName","icon":"icon-property"},{"fullName":"Injector","url":"#!/api/Injector","sort":1,"meta":{},"name":"Injector","icon":"icon-class"},{"fullName":"Injector.constructor","url":"#!/api/Injector-method-constructor","sort":3,"meta":{},"name":"constructor","icon":"icon-method"},{"fullName":"Injector.addMapping","url":"#!/api/Injector-method-addMapping","sort":3,"meta":{},"name":"addMapping","icon":"icon-method"},{"fullName":"Injector.bind","url":"#!/api/Injector-method-bind","sort":3,"meta":{"private":true},"name":"bind","icon":"icon-method"},{"fullName":"Injector.cancelInjectionsInto","url":"#!/api/Injector-method-cancelInjectionsInto","sort":3,"meta":{},"name":"cancelInjectionsInto","icon":"icon-method"},{"fullName":"Injector.createInjectedInstance","url":"#!/api/Injector-method-createInjectedInstance","sort":3,"meta":{},"name":"createInjectedInstance","icon":"icon-method"},{"fullName":"Injector.getArgumentNames","url":"#!/api/Injector-method-getArgumentNames","sort":3,"meta":{"private":true},"name":"getArgumentNames","icon":"icon-method"},{"fullName":"Injector.getMapping","url":"#!/api/Injector-method-getMapping","sort":3,"meta":{},"name":"getMapping","icon":"icon-method"},{"fullName":"Injector.hasMapping","url":"#!/api/Injector-method-hasMapping","sort":3,"meta":{},"name":"hasMapping","icon":"icon-method"},{"fullName":"Injector.injectInto","url":"#!/api/Injector-method-injectInto","sort":3,"meta":{},"name":"injectInto","icon":"icon-method"},{"fullName":"Injector.parseStr","url":"#!/api/Injector-method-parseStr","sort":3,"meta":{},"name":"parseStr","icon":"icon-method"},{"fullName":"Injector.removeMapping","url":"#!/api/Injector-method-removeMapping","sort":3,"meta":{},"name":"removeMapping","icon":"icon-method"},{"fullName":"Injector.resolveInjections","url":"#!/api/Injector-method-resolveInjections","sort":3,"meta":{},"name":"resolveInjections","icon":"icon-method"},{"fullName":"Injector.triggerFunctionWithInjectedParams","url":"#!/api/Injector-method-triggerFunctionWithInjectedParams","sort":3,"meta":{},"name":"triggerFunctionWithInjectedParams","icon":"icon-method"},{"fullName":"Injector.","url":"#!/api/Injector-property-","sort":3,"meta":{"private":true},"name":"","icon":"icon-property"},{"fullName":"Injector.instancePostInjectionsCallbackName","url":"#!/api/Injector-property-instancePostInjectionsCallbackName","sort":3,"meta":{},"name":"instancePostInjectionsCallbackName","icon":"icon-property"}],"source":true,"showPrintButton":false,"tests":false,"signatures":[{"short":"ABS","long":"abstract","key":"abstract"},{"short":">","long":"chainable","key":"chainable"},{"short":"DEP","long":"deprecated","key":"deprecated"},{"short":"★","long":"★","key":"new"},{"short":"PREV","long":"preventable","key":"preventable"},{"short":"PRI","long":"private","key":"private"},{"short":"PRO","long":"protected","key":"protected"},{"short":"R O","long":"readonly","key":"readonly"},{"short":"REM","long":"removed","key":"removed"},{"short":"REQ","long":"required","key":"required"},{"short":"STA","long":"static","key":"static"},{"short":"TMP","long":"template","key":"template"}],"stats":[],"classes":[{"extends":null,"private":null,"name":"InjectionMapping","icon":"icon-class"},{"extends":null,"private":null,"name":"Injector","icon":"icon-class"}],"touchExamplesUi":false,"videos":[],"localStorageDb":"docs","examples":[]}};
+Docs = {"data":{"guides":[],"search":[{"fullName":"InjectionMapping","url":"#!/api/InjectionMapping","sort":1,"meta":{},"name":"InjectionMapping","icon":"icon-class"},{"fullName":"InjectionMapping.constructor","url":"#!/api/InjectionMapping-method-constructor","sort":3,"meta":{},"name":"constructor","icon":"icon-method"},{"fullName":"InjectionMapping._onAsyncResolutionInSingletonMode","url":"#!/api/InjectionMapping-method-_onAsyncResolutionInSingletonMode","sort":3,"meta":{"private":true},"name":"_onAsyncResolutionInSingletonMode","icon":"icon-method"},{"fullName":"InjectionMapping._resolveModule","url":"#!/api/InjectionMapping-method-_resolveModule","sort":3,"meta":{"private":true},"name":"_resolveModule","icon":"icon-method"},{"fullName":"InjectionMapping._resolveProvider","url":"#!/api/InjectionMapping-method-_resolveProvider","sort":3,"meta":{"private":true},"name":"_resolveProvider","icon":"icon-method"},{"fullName":"InjectionMapping._throwSealedException","url":"#!/api/InjectionMapping-method-_throwSealedException","sort":3,"meta":{"private":true},"name":"_throwSealedException","icon":"icon-method"},{"fullName":"InjectionMapping._triggerFunction","url":"#!/api/InjectionMapping-method-_triggerFunction","sort":3,"meta":{"private":true},"name":"_triggerFunction","icon":"icon-method"},{"fullName":"InjectionMapping._triggerInjectionResolutionCallback","url":"#!/api/InjectionMapping-method-_triggerInjectionResolutionCallback","sort":3,"meta":{"private":true},"name":"_triggerInjectionResolutionCallback","icon":"icon-method"},{"fullName":"InjectionMapping.asSingleton","url":"#!/api/InjectionMapping-method-asSingleton","sort":3,"meta":{},"name":"asSingleton","icon":"icon-method"},{"fullName":"InjectionMapping.isSealed","url":"#!/api/InjectionMapping-method-isSealed","sort":3,"meta":{},"name":"isSealed","icon":"icon-method"},{"fullName":"InjectionMapping.resolveInjection","url":"#!/api/InjectionMapping-method-resolveInjection","sort":3,"meta":{},"name":"resolveInjection","icon":"icon-method"},{"fullName":"InjectionMapping.seal","url":"#!/api/InjectionMapping-method-seal","sort":3,"meta":{},"name":"seal","icon":"icon-method"},{"fullName":"InjectionMapping.toModule","url":"#!/api/InjectionMapping-method-toModule","sort":3,"meta":{},"name":"toModule","icon":"icon-method"},{"fullName":"InjectionMapping.toProvider","url":"#!/api/InjectionMapping-method-toProvider","sort":3,"meta":{},"name":"toProvider","icon":"icon-method"},{"fullName":"InjectionMapping.toType","url":"#!/api/InjectionMapping-method-toType","sort":3,"meta":{},"name":"toType","icon":"icon-method"},{"fullName":"InjectionMapping.toValue","url":"#!/api/InjectionMapping-method-toValue","sort":3,"meta":{},"name":"toValue","icon":"icon-method"},{"fullName":"InjectionMapping.unseal","url":"#!/api/InjectionMapping-method-unseal","sort":3,"meta":{},"name":"unseal","icon":"icon-method"},{"fullName":"InjectionMapping.injectionName","url":"#!/api/InjectionMapping-property-injectionName","sort":3,"meta":{},"name":"injectionName","icon":"icon-property"},{"fullName":"Injector","url":"#!/api/Injector","sort":1,"meta":{},"name":"Injector","icon":"icon-class"},{"fullName":"Injector.constructor","url":"#!/api/Injector-method-constructor","sort":3,"meta":{},"name":"constructor","icon":"icon-method"},{"fullName":"Injector.addMapping","url":"#!/api/Injector-method-addMapping","sort":3,"meta":{},"name":"addMapping","icon":"icon-method"},{"fullName":"Injector.bind","url":"#!/api/Injector-method-bind","sort":3,"meta":{"private":true},"name":"bind","icon":"icon-method"},{"fullName":"Injector.cancelInjectionsInto","url":"#!/api/Injector-method-cancelInjectionsInto","sort":3,"meta":{},"name":"cancelInjectionsInto","icon":"icon-method"},{"fullName":"Injector.createInjectedInstance","url":"#!/api/Injector-method-createInjectedInstance","sort":3,"meta":{},"name":"createInjectedInstance","icon":"icon-method"},{"fullName":"Injector.getArgumentNames","url":"#!/api/Injector-method-getArgumentNames","sort":3,"meta":{"private":true},"name":"getArgumentNames","icon":"icon-method"},{"fullName":"Injector.getMapping","url":"#!/api/Injector-method-getMapping","sort":3,"meta":{},"name":"getMapping","icon":"icon-method"},{"fullName":"Injector.hasMapping","url":"#!/api/Injector-method-hasMapping","sort":3,"meta":{},"name":"hasMapping","icon":"icon-method"},{"fullName":"Injector.injectInto","url":"#!/api/Injector-method-injectInto","sort":3,"meta":{},"name":"injectInto","icon":"icon-method"},{"fullName":"Injector.parseStr","url":"#!/api/Injector-method-parseStr","sort":3,"meta":{},"name":"parseStr","icon":"icon-method"},{"fullName":"Injector.removeMapping","url":"#!/api/Injector-method-removeMapping","sort":3,"meta":{},"name":"removeMapping","icon":"icon-method"},{"fullName":"Injector.resolveInjections","url":"#!/api/Injector-method-resolveInjections","sort":3,"meta":{},"name":"resolveInjections","icon":"icon-method"},{"fullName":"Injector.triggerFunctionWithInjectedParams","url":"#!/api/Injector-method-triggerFunctionWithInjectedParams","sort":3,"meta":{},"name":"triggerFunctionWithInjectedParams","icon":"icon-method"},{"fullName":"Injector.","url":"#!/api/Injector-property-","sort":3,"meta":{"private":true},"name":"","icon":"icon-property"},{"fullName":"Injector.instancePostInjectionsCallbackName","url":"#!/api/Injector-property-instancePostInjectionsCallbackName","sort":3,"meta":{},"name":"instancePostInjectionsCallbackName","icon":"icon-property"},{"fullName":"sync.InjectionMapping","url":"#!/api/sync.InjectionMapping","sort":1,"meta":{},"name":"InjectionMapping","icon":"icon-class"},{"fullName":"sync.InjectionMapping.constructor","url":"#!/api/sync.InjectionMapping-method-constructor","sort":3,"meta":{},"name":"constructor","icon":"icon-method"},{"fullName":"sync.InjectionMapping._throwSealedException","url":"#!/api/sync.InjectionMapping-method-_throwSealedException","sort":3,"meta":{"private":true},"name":"_throwSealedException","icon":"icon-method"},{"fullName":"sync.InjectionMapping.asSingleton","url":"#!/api/sync.InjectionMapping-method-asSingleton","sort":3,"meta":{},"name":"asSingleton","icon":"icon-method"},{"fullName":"sync.InjectionMapping.isSealed","url":"#!/api/sync.InjectionMapping-method-isSealed","sort":3,"meta":{},"name":"isSealed","icon":"icon-method"},{"fullName":"sync.InjectionMapping.resolveInjection","url":"#!/api/sync.InjectionMapping-method-resolveInjection","sort":3,"meta":{},"name":"resolveInjection","icon":"icon-method"},{"fullName":"sync.InjectionMapping.seal","url":"#!/api/sync.InjectionMapping-method-seal","sort":3,"meta":{},"name":"seal","icon":"icon-method"},{"fullName":"sync.InjectionMapping.toProvider","url":"#!/api/sync.InjectionMapping-method-toProvider","sort":3,"meta":{},"name":"toProvider","icon":"icon-method"},{"fullName":"sync.InjectionMapping.toType","url":"#!/api/sync.InjectionMapping-method-toType","sort":3,"meta":{},"name":"toType","icon":"icon-method"},{"fullName":"sync.InjectionMapping.toValue","url":"#!/api/sync.InjectionMapping-method-toValue","sort":3,"meta":{},"name":"toValue","icon":"icon-method"},{"fullName":"sync.InjectionMapping.unseal","url":"#!/api/sync.InjectionMapping-method-unseal","sort":3,"meta":{},"name":"unseal","icon":"icon-method"},{"fullName":"sync.InjectionMapping.injectionName","url":"#!/api/sync.InjectionMapping-property-injectionName","sort":3,"meta":{},"name":"injectionName","icon":"icon-property"},{"fullName":"sync.Injector","url":"#!/api/sync.Injector","sort":1,"meta":{},"name":"Injector","icon":"icon-class"},{"fullName":"sync.Injector.constructor","url":"#!/api/sync.Injector-method-constructor","sort":3,"meta":{},"name":"constructor","icon":"icon-method"},{"fullName":"sync.Injector.addMapping","url":"#!/api/sync.Injector-method-addMapping","sort":3,"meta":{},"name":"addMapping","icon":"icon-method"},{"fullName":"sync.Injector.bind","url":"#!/api/sync.Injector-method-bind","sort":3,"meta":{"private":true},"name":"bind","icon":"icon-method"},{"fullName":"sync.Injector.cancelInjectionsInto","url":"#!/api/sync.Injector-method-cancelInjectionsInto","sort":3,"meta":{},"name":"cancelInjectionsInto","icon":"icon-method"},{"fullName":"sync.Injector.createInjectedInstance","url":"#!/api/sync.Injector-method-createInjectedInstance","sort":3,"meta":{},"name":"createInjectedInstance","icon":"icon-method"},{"fullName":"sync.Injector.getArgumentNames","url":"#!/api/sync.Injector-method-getArgumentNames","sort":3,"meta":{"private":true},"name":"getArgumentNames","icon":"icon-method"},{"fullName":"sync.Injector.getMapping","url":"#!/api/sync.Injector-method-getMapping","sort":3,"meta":{},"name":"getMapping","icon":"icon-method"},{"fullName":"sync.Injector.hasMapping","url":"#!/api/sync.Injector-method-hasMapping","sort":3,"meta":{},"name":"hasMapping","icon":"icon-method"},{"fullName":"sync.Injector.injectInto","url":"#!/api/sync.Injector-method-injectInto","sort":3,"meta":{},"name":"injectInto","icon":"icon-method"},{"fullName":"sync.Injector.parseStr","url":"#!/api/sync.Injector-method-parseStr","sort":3,"meta":{},"name":"parseStr","icon":"icon-method"},{"fullName":"sync.Injector.removeMapping","url":"#!/api/sync.Injector-method-removeMapping","sort":3,"meta":{},"name":"removeMapping","icon":"icon-method"},{"fullName":"sync.Injector.resolveInjections","url":"#!/api/sync.Injector-method-resolveInjections","sort":3,"meta":{},"name":"resolveInjections","icon":"icon-method"},{"fullName":"sync.Injector.triggerFunctionWithInjectedParams","url":"#!/api/sync.Injector-method-triggerFunctionWithInjectedParams","sort":3,"meta":{},"name":"triggerFunctionWithInjectedParams","icon":"icon-method"},{"fullName":"sync.Injector.instancePostInjectionsCallbackName","url":"#!/api/sync.Injector-property-instancePostInjectionsCallbackName","sort":3,"meta":{},"name":"instancePostInjectionsCallbackName","icon":"icon-property"}],"source":true,"showPrintButton":false,"tests":false,"signatures":[{"short":"ABS","long":"abstract","key":"abstract"},{"short":">","long":"chainable","key":"chainable"},{"short":"DEP","long":"deprecated","key":"deprecated"},{"short":"★","long":"★","key":"new"},{"short":"PREV","long":"preventable","key":"preventable"},{"short":"PRI","long":"private","key":"private"},{"short":"PRO","long":"protected","key":"protected"},{"short":"R O","long":"readonly","key":"readonly"},{"short":"REM","long":"removed","key":"removed"},{"short":"REQ","long":"required","key":"required"},{"short":"STA","long":"static","key":"static"},{"short":"TMP","long":"template","key":"template"}],"stats":[],"classes":[{"extends":null,"private":null,"name":"InjectionMapping","icon":"icon-class"},{"extends":null,"private":null,"name":"Injector","icon":"icon-class"},{"extends":null,"private":null,"name":"sync.InjectionMapping","icon":"icon-class"},{"extends":null,"private":null,"name":"sync.Injector","icon":"icon-class"}],"touchExamplesUi":false,"videos":[],"localStorageDb":"docs","examples":[]}};
View
15 docs/api/index.html
@@ -29,6 +29,21 @@
<div id='categories-content' style='display:none'>
<div class='section'>
+<h1>sync</h1>
+<div class='left-column'>
+<h3>Others...</h3>
+<div class='links'>
+<a href="#!/api/sync.InjectionMapping" rel="sync.InjectionMapping" class="docClass">sync.InjectionMapping</a>
+<a href="#!/api/sync.Injector" rel="sync.Injector" class="docClass">sync.Injector</a>
+</div>
+</div>
+<div class='middle-column'>
+</div>
+<div class='right-column'>
+</div>
+<div style='clear:both'></div>
+</div>
+<div class='section'>
<h1>Others...</h1>
<div class='left-column'>
<h3>Others...</h3>
View
2  docs/api/output/InjectionMapping.js
@@ -1 +1 @@
-Ext.data.JsonP.InjectionMapping({"parentMixins":[],"inheritable":null,"html":"<div><pre class=\"hierarchy\"><h4>Files</h4><div class='dependency'><a href='source/medic-injector.html#InjectionMapping' target='_blank'>medic-injector.js</a></div><div class='dependency'><a href='source/medic-injector.html#InjectionMapping' target='_blank'>medic-injector.js</a></div></pre><div class='doc-contents'><p>You cant' use this constructor directly. Use <a href=\"#!/api/Injector-method-addMapping\" rel=\"Injector-method-addMapping\" class=\"docClass\">Injector.addMapping</a> to create a new Injection Mapping.</p>\n</div><div class='members'><div class='members-section'><div class='definedBy'>Defined By</div><h3 class='members-title icon-property'>Properties</h3><div class='subsection'><div id='property-injectionName' class='member first-child not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-property-injectionName' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-property-injectionName' class='name not-expandable'>injectionName</a><span> : String</span></div><div class='description'><div class='short'>\n</div><div class='long'>\n</div></div></div></div></div><div class='members-section'><div class='definedBy'>Defined By</div><h3 class='members-title icon-method'>Methods</h3><div class='subsection'><div id='method-constructor' class='member first-child not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-constructor' target='_blank' class='view-source'>view source</a></div><strong class='new-keyword'>new</strong><a href='#!/api/InjectionMapping-method-constructor' class='name expandable'>InjectionMapping</a>( <span class='pre'><a href=\"#!/api/Injector\" rel=\"Injector\" class=\"docClass\">Injector</a> injectorInstance, String injectionName</span> ) : <a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></div><div class='description'><div class='short'> ...</div><div class='long'>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>injectorInstance</span> : <a href=\"#!/api/Injector\" rel=\"Injector\" class=\"docClass\">Injector</a><div class='sub-desc'>\n</div></li><li><span class='pre'>injectionName</span> : String<div class='sub-desc'>\n</div></li></ul><h3 class='pa'>Returns</h3><ul><li><span class='pre'><a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></span><div class='sub-desc'>\n</div></li></ul></div></div></div><div id='method-_onAsyncResolutionInSingletonMode' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-_onAsyncResolutionInSingletonMode' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-_onAsyncResolutionInSingletonMode' class='name expandable'>_onAsyncResolutionInSingletonMode</a>( <span class='pre'>Object injectionResolvedValue</span> )<strong class='private signature' >private</strong></div><div class='description'><div class='short'> ...</div><div class='long'>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>injectionResolvedValue</span> : Object<div class='sub-desc'>\n</div></li></ul></div></div></div><div id='method-_resolveModule' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-_resolveModule' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-_resolveModule' class='name expandable'>_resolveModule</a>( <span class='pre'>Function callback, [Object context], [Boolean forceAsync]</span> )<strong class='private signature' >private</strong></div><div class='description'><div class='short'> ...</div><div class='long'>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>callback</span> : Function<div class='sub-desc'>\n</div></li><li><span class='pre'>context</span> : Object (optional)<div class='sub-desc'>\n<p>Defaults to: <code>null</code></p></div></li><li><span class='pre'>forceAsync</span> : Boolean (optional)<div class='sub-desc'>\n<p>Defaults to: <code>false</code></p></div></li></ul></div></div></div><div id='method-_resolveProvider' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-_resolveProvider' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-_resolveProvider' class='name expandable'>_resolveProvider</a>( <span class='pre'>Function callback, [Object context], [Boolean forceAsync]</span> )<strong class='private signature' >private</strong></div><div class='description'><div class='short'>Recursive resolution of a \"provider\" injection. ...</div><div class='long'><p>Recursive resolution of a \"provider\" injection. Any of this provider function's argument whose name equals a registered\ninjection name will itself trigger a recursive injection resolution.</p>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>callback</span> : Function<div class='sub-desc'>\n</div></li><li><span class='pre'>context</span> : Object (optional)<div class='sub-desc'>\n<p>Defaults to: <code>null</code></p></div></li><li><span class='pre'>forceAsync</span> : Boolean (optional)<div class='sub-desc'>\n<p>Defaults to: <code>false</code></p></div></li></ul></div></div></div><div id='method-_throwSealedException' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-_throwSealedException' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-_throwSealedException' class='name expandable'>_throwSealedException</a>( <span class='pre'></span> )<strong class='private signature' >private</strong></div><div class='description'><div class='short'> ...</div><div class='long'>\n</div></div></div><div id='method-_triggerFunction' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-_triggerFunction' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-_triggerFunction' class='name expandable'>_triggerFunction</a>( <span class='pre'>Function func, Array argsArray, [Object context], [Boolean forceAsync]</span> )<strong class='private signature' >private</strong></div><div class='description'><div class='short'> ...</div><div class='long'>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>func</span> : Function<div class='sub-desc'>\n</div></li><li><span class='pre'>argsArray</span> : Array<div class='sub-desc'>\n</div></li><li><span class='pre'>context</span> : Object (optional)<div class='sub-desc'>\n<p>Defaults to: <code>null</code></p></div></li><li><span class='pre'>forceAsync</span> : Boolean (optional)<div class='sub-desc'>\n<p>Defaults to: <code>false</code></p></div></li></ul></div></div></div><div id='method-_triggerInjectionResolutionCallback' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-_triggerInjectionResolutionCallback' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-_triggerInjectionResolutionCallback' class='name expandable'>_triggerInjectionResolutionCallback</a>( <span class='pre'>Object injectionResolvedValue, Function callback, [Object context], [Boolean forceAsync]</span> )<strong class='private signature' >private</strong></div><div class='description'><div class='short'>an Error will be thrown if the callback function have more than 1 arg and none of them is called \"injectionName\" ...</div><div class='long'><p>an Error will be thrown if the callback function have more than 1 arg and none of them is called \"injectionName\"</p>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>injectionResolvedValue</span> : Object<div class='sub-desc'>\n</div></li><li><span class='pre'>callback</span> : Function<div class='sub-desc'>\n</div></li><li><span class='pre'>context</span> : Object (optional)<div class='sub-desc'>\n<p>Defaults to: <code>null</code></p></div></li><li><span class='pre'>forceAsync</span> : Boolean (optional)<div class='sub-desc'>\n<p>Defaults to: <code>false</code></p></div></li></ul><h3 class='pa'>Throws</h3><ul><li><span class='pre'>Error</span><div class='sub-desc'><p>an Error will be thrown if the callback function have more than 1 arg and none of them is called \"injectionName\"</p>\n</div></li></ul></div></div></div><div id='method-asSingleton' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-asSingleton' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-asSingleton' class='name expandable'>asSingleton</a>( <span class='pre'></span> ) : <a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></div><div class='description'><div class='short'>When this method is called on an Injection Mapping, its resolution will be triggered the first time it is\nrequested, ...</div><div class='long'><p>When this method is called on an Injection Mapping, its resolution will be triggered the first time it is\nrequested, but any subsequent call will use this first-time resolved value.</p>\n<h3 class='pa'>Returns</h3><ul><li><span class='pre'><a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></span><div class='sub-desc'><p>The <code>InjectionMapping</code> the method is invoked on</p>\n</div></li></ul><h3 class='pa'>Throws</h3><ul><li><span class='pre'>Error</span><div class='sub-desc'>\n</div></li></ul></div></div></div><div id='method-isSealed' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-isSealed' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-isSealed' class='name expandable'>isSealed</a>( <span class='pre'></span> ) : Boolean</div><div class='description'><div class='short'>If the seal method has been called on this InjectionMapping, returns true ...</div><div class='long'><p>If the <a href=\"#!/api/InjectionMapping-method-seal\" rel=\"InjectionMapping-method-seal\" class=\"docClass\">seal</a> method has been called on this InjectionMapping, returns <code>true</code></p>\n<h3 class='pa'>Returns</h3><ul><li><span class='pre'>Boolean</span><div class='sub-desc'>\n</div></li></ul></div></div></div><div id='method-resolveInjection' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-resolveInjection' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-resolveInjection' class='name expandable'>resolveInjection</a>( <span class='pre'>Function callback, [Object context], [Boolean forceAsync]</span> )</div><div class='description'><div class='short'>Resolves the injection mapping. ...</div><div class='long'><p>Resolves the injection mapping.\nWhen it's resolved, the callback function is triggered in the supplied context.\nThe first arg of the triggered callback will be the injection value. If you have anothers\nargs in the callback function, they will be inspected and may be filled with other injections values too,\nfor each of these function arg whose name s the same that an existing InjectionMapping.</p>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>callback</span> : Function<div class='sub-desc'>\n</div></li><li><span class='pre'>context</span> : Object (optional)<div class='sub-desc'>\n<p>Defaults to: <code>null</code></p></div></li><li><span class='pre'>forceAsync</span> : Boolean (optional)<div class='sub-desc'>\n<p>Defaults to: <code>false</code></p></div></li></ul></div></div></div><div id='method-seal' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-seal' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-seal' class='name expandable'>seal</a>( <span class='pre'></span> ) : Object</div><div class='description'><div class='short'>Seal this Injection mapping. ...</div><div class='long'><p>Seal this Injection mapping. Any subsequent call to any of the</p>\n\n<h1>toValue, \"toProvider()\", \"toModule\" or \"asSingleton()\" methods will throw</h1>\n\n<p>an Error. @see <a href=\"#!/api/InjectionMapping-method-unseal\" rel=\"InjectionMapping-method-unseal\" class=\"docClass\">unseal</a>()</p>\n<h3 class='pa'>Returns</h3><ul><li><span class='pre'>Object</span><div class='sub-desc'><p>returns a \"unseal\" key ; the only way to unseal this InjectionMapping it to call its \"unseal()\" method with this key</p>\n</div></li></ul><h3 class='pa'>Throws</h3><ul><li><span class='pre'>Error</span><div class='sub-desc'><p>@see <a href=\"#!/api/InjectionMapping-method-unseal\" rel=\"InjectionMapping-method-unseal\" class=\"docClass\">unseal</a>()</p>\n</div></li></ul></div></div></div><div id='method-toModule' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-toModule' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-toModule' class='name expandable'>toModule</a>( <span class='pre'>String modulePathToRequire, [String targetModulePropertyName]</span> ) : <a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></div><div class='description'><div class='short'>Maps an injection value to the result of a module. ...</div><div class='long'><p>Maps an injection value to the result of a module.\nUse this only in Node.js or AMD environments (needs the presence of a global \"require\" function).\n@see https://github.com/amdjs/amdjs-api/wiki/AMD</p>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>modulePathToRequire</span> : String<div class='sub-desc'>\n</div></li><li><span class='pre'>targetModulePropertyName</span> : String (optional)<div class='sub-desc'>\n<p>Defaults to: <code>null</code></p></div></li></ul><h3 class='pa'>Returns</h3><ul><li><span class='pre'><a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></span><div class='sub-desc'><p>The <code>InjectionMapping</code> the method is invoked on</p>\n</div></li></ul><h3 class='pa'>Throws</h3><ul><li><span class='pre'>Error</span><div class='sub-desc'>\n</div></li></ul></div></div></div><div id='method-toProvider' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-toProvider' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-toProvider' class='name expandable'>toProvider</a>( <span class='pre'>Function injectionValueProviderFunction</span> ) : <a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></div><div class='description'><div class='short'>The Injection Mapping value will be resolved through a Provider function. ...</div><div class='long'><p>The Injection Mapping value will be resolved through a Provider function.\nIf this function has a \"callback\" argument, it will be considered as an asynchronous Provider.</p>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>injectionValueProviderFunction</span> : Function<div class='sub-desc'>\n</div></li></ul><h3 class='pa'>Returns</h3><ul><li><span class='pre'><a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></span><div class='sub-desc'><p>The <code>InjectionMapping</code> the method is invoked on</p>\n</div></li></ul><h3 class='pa'>Throws</h3><ul><li><span class='pre'>Error</span><div class='sub-desc'>\n</div></li></ul></div></div></div><div id='method-toType' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-toType' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-toType' class='name expandable'>toType</a>( <span class='pre'>Function javascriptType</span> ) : <a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></div><div class='description'><div class='short'>Each time this Injection Mapping value will be requested, a new instance of the target Javascript type will\nbe created. ...</div><div class='long'><p>Each time this Injection Mapping value will be requested, a new instance of the target Javascript type will\nbe created.\nUse it with <a href=\"#!/api/InjectionMapping-method-asSingleton\" rel=\"InjectionMapping-method-asSingleton\" class=\"docClass\">asSingleton</a>() to map a lazy-loaded shared instance to this Injection Mapping.</p>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>javascriptType</span> : Function<div class='sub-desc'>\n</div></li></ul><h3 class='pa'>Returns</h3><ul><li><span class='pre'><a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></span><div class='sub-desc'><p>The <code>InjectionMapping</code> the method is invoked on</p>\n</div></li></ul><h3 class='pa'>Throws</h3><ul><li><span class='pre'>Error</span><div class='sub-desc'>\n</div></li></ul></div></div></div><div id='method-toValue' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-toValue' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-toValue' class='name expandable'>toValue</a>( <span class='pre'>Object value</span> ) : <a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></div><div class='description'><div class='short'>The simplest Injection Mapping type : each time a component will request this Injection Mapping injection, the\ntarget...</div><div class='long'><p>The simplest Injection Mapping type : each time a component will request this Injection Mapping injection, the\ntarget value will be injected.\nSince this value is a plain Javascript scalar, Array or Object, it's shared in all the application and calling</p>\n\n<h1>asSingleton on such an Injection Mapping is useless.</h1>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>value</span> : Object<div class='sub-desc'>\n</div></li></ul><h3 class='pa'>Returns</h3><ul><li><span class='pre'><a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></span><div class='sub-desc'><p>The <code>InjectionMapping</code> the method is invoked on</p>\n</div></li></ul><h3 class='pa'>Throws</h3><ul><li><span class='pre'>Error</span><div class='sub-desc'>\n</div></li></ul></div></div></div><div id='method-unseal' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-unseal' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-unseal' class='name expandable'>unseal</a>( <span class='pre'>Object key</span> ) : <a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></div><div class='description'><div class='short'>Reverts the effect of seal, makes the mapping changeable again. ...</div><div class='long'><p>Reverts the effect of <code>seal</code>, makes the mapping changeable again. Has to be invoked with the unique key object returned by an earlier call to <code>seal</code> Can't unseal a mapping that's not sealed\n@see <a href=\"#!/api/InjectionMapping-method-seal\" rel=\"InjectionMapping-method-seal\" class=\"docClass\">seal</a>()</p>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>key</span> : Object<div class='sub-desc'><p>The key to unseal the mapping. Has to be the instance returned by\n<code>seal()</code></p>\n</div></li></ul><h3 class='pa'>Returns</h3><ul><li><span class='pre'><a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></span><div class='sub-desc'><p>The <code>InjectionMapping</code> the method is invoked on</p>\n</div></li></ul><h3 class='pa'>Throws</h3><ul><li><span class='pre'>Error</span><div class='sub-desc'><p>Has to be invoked with the unique key object returned by an earlier call to <code>seal</code></p>\n</div></li><li><span class='pre'>Error</span><div class='sub-desc'><p>Can't unseal a mapping that's not sealed\n@see <a href=\"#!/api/InjectionMapping-method-seal\" rel=\"InjectionMapping-method-seal\" class=\"docClass\">seal</a>()</p>\n</div></li></ul></div></div></div></div></div></div></div>","override":null,"extends":null,"html_meta":{},"uses":[],"alternateClassNames":[],"members":{"method":[{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"constructor","id":"method-constructor"},{"tagname":"method","meta":{"private":true},"owner":"InjectionMapping","name":"_onAsyncResolutionInSingletonMode","id":"method-_onAsyncResolutionInSingletonMode"},{"tagname":"method","meta":{"private":true},"owner":"InjectionMapping","name":"_resolveModule","id":"method-_resolveModule"},{"tagname":"method","meta":{"private":true},"owner":"InjectionMapping","name":"_resolveProvider","id":"method-_resolveProvider"},{"tagname":"method","meta":{"private":true},"owner":"InjectionMapping","name":"_throwSealedException","id":"method-_throwSealedException"},{"tagname":"method","meta":{"private":true},"owner":"InjectionMapping","name":"_triggerFunction","id":"method-_triggerFunction"},{"tagname":"method","meta":{"private":true},"owner":"InjectionMapping","name":"_triggerInjectionResolutionCallback","id":"method-_triggerInjectionResolutionCallback"},{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"asSingleton","id":"method-asSingleton"},{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"isSealed","id":"method-isSealed"},{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"resolveInjection","id":"method-resolveInjection"},{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"seal","id":"method-seal"},{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"toModule","id":"method-toModule"},{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"toProvider","id":"method-toProvider"},{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"toType","id":"method-toType"},{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"toValue","id":"method-toValue"},{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"unseal","id":"method-unseal"}],"cfg":[],"property":[{"tagname":"property","meta":{},"owner":"InjectionMapping","name":"injectionName","id":"property-injectionName"}],"css_var":[],"event":[],"css_mixin":[]},"subclasses":[],"superclasses":[],"singleton":false,"tagname":"class","statics":{"method":[],"cfg":[],"property":[],"css_var":[],"event":[],"css_mixin":[]},"requires":[],"mixins":[],"private":null,"component":false,"meta":{},"name":"InjectionMapping","linenr":17,"files":[{"href":"medic-injector.html#InjectionMapping","filename":"medic-injector.js"},{"href":"medic-injector.html#InjectionMapping","filename":"medic-injector.js"}],"inheritdoc":null,"enum":null,"id":"class-InjectionMapping","mixedInto":[],"aliases":{}});
+Ext.data.JsonP.InjectionMapping({"parentMixins":[],"inheritable":null,"html":"<div><pre class=\"hierarchy\"><h4>Files</h4><div class='dependency'><a href='source/medic-injector.html#InjectionMapping' target='_blank'>medic-injector.js</a></div><div class='dependency'><a href='source/medic-injector.html#InjectionMapping' target='_blank'>medic-injector.js</a></div><div class='dependency'><a href='source/medic-injector.sync.html#InjectionMapping' target='_blank'>medic-injector.sync.js</a></div></pre><div class='doc-contents'><p>You cant' use this constructor directly. Use <a href=\"#!/api/Injector-method-addMapping\" rel=\"Injector-method-addMapping\" class=\"docClass\">Injector.addMapping</a> to create a new Injection Mapping.</p>\n</div><div class='members'><div class='members-section'><div class='definedBy'>Defined By</div><h3 class='members-title icon-property'>Properties</h3><div class='subsection'><div id='property-injectionName' class='member first-child not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-property-injectionName' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-property-injectionName' class='name not-expandable'>injectionName</a><span> : String</span></div><div class='description'><div class='short'>\n</div><div class='long'>\n</div></div></div></div></div><div class='members-section'><div class='definedBy'>Defined By</div><h3 class='members-title icon-method'>Methods</h3><div class='subsection'><div id='method-constructor' class='member first-child not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-constructor' target='_blank' class='view-source'>view source</a></div><strong class='new-keyword'>new</strong><a href='#!/api/InjectionMapping-method-constructor' class='name expandable'>InjectionMapping</a>( <span class='pre'><a href=\"#!/api/Injector\" rel=\"Injector\" class=\"docClass\">Injector</a> injectorInstance, String injectionName</span> ) : <a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></div><div class='description'><div class='short'> ...</div><div class='long'>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>injectorInstance</span> : <a href=\"#!/api/Injector\" rel=\"Injector\" class=\"docClass\">Injector</a><div class='sub-desc'>\n</div></li><li><span class='pre'>injectionName</span> : String<div class='sub-desc'>\n</div></li></ul><h3 class='pa'>Returns</h3><ul><li><span class='pre'><a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></span><div class='sub-desc'>\n</div></li></ul></div></div></div><div id='method-_onAsyncResolutionInSingletonMode' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-_onAsyncResolutionInSingletonMode' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-_onAsyncResolutionInSingletonMode' class='name expandable'>_onAsyncResolutionInSingletonMode</a>( <span class='pre'>Object injectionResolvedValue</span> )<strong class='private signature' >private</strong></div><div class='description'><div class='short'> ...</div><div class='long'>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>injectionResolvedValue</span> : Object<div class='sub-desc'>\n</div></li></ul></div></div></div><div id='method-_resolveModule' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-_resolveModule' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-_resolveModule' class='name expandable'>_resolveModule</a>( <span class='pre'>Function callback, [Object context], [Boolean forceAsync]</span> )<strong class='private signature' >private</strong></div><div class='description'><div class='short'> ...</div><div class='long'>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>callback</span> : Function<div class='sub-desc'>\n</div></li><li><span class='pre'>context</span> : Object (optional)<div class='sub-desc'>\n<p>Defaults to: <code>null</code></p></div></li><li><span class='pre'>forceAsync</span> : Boolean (optional)<div class='sub-desc'>\n<p>Defaults to: <code>false</code></p></div></li></ul></div></div></div><div id='method-_resolveProvider' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-_resolveProvider' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-_resolveProvider' class='name expandable'>_resolveProvider</a>( <span class='pre'>Function callback, [Object context], [Boolean forceAsync]</span> )<strong class='private signature' >private</strong></div><div class='description'><div class='short'>Recursive resolution of a \"provider\" injection. ...</div><div class='long'><p>Recursive resolution of a \"provider\" injection. Any of this provider function's argument whose name equals a registered\ninjection name will itself trigger a recursive injection resolution.</p>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>callback</span> : Function<div class='sub-desc'>\n</div></li><li><span class='pre'>context</span> : Object (optional)<div class='sub-desc'>\n<p>Defaults to: <code>null</code></p></div></li><li><span class='pre'>forceAsync</span> : Boolean (optional)<div class='sub-desc'>\n<p>Defaults to: <code>false</code></p></div></li></ul></div></div></div><div id='method-_throwSealedException' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-_throwSealedException' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-_throwSealedException' class='name expandable'>_throwSealedException</a>( <span class='pre'></span> )<strong class='private signature' >private</strong></div><div class='description'><div class='short'> ...</div><div class='long'>\n</div></div></div><div id='method-_triggerFunction' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-_triggerFunction' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-_triggerFunction' class='name expandable'>_triggerFunction</a>( <span class='pre'>Function func, Array argsArray, [Object context], [Boolean forceAsync]</span> )<strong class='private signature' >private</strong></div><div class='description'><div class='short'> ...</div><div class='long'>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>func</span> : Function<div class='sub-desc'>\n</div></li><li><span class='pre'>argsArray</span> : Array<div class='sub-desc'>\n</div></li><li><span class='pre'>context</span> : Object (optional)<div class='sub-desc'>\n<p>Defaults to: <code>null</code></p></div></li><li><span class='pre'>forceAsync</span> : Boolean (optional)<div class='sub-desc'>\n<p>Defaults to: <code>false</code></p></div></li></ul></div></div></div><div id='method-_triggerInjectionResolutionCallback' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-_triggerInjectionResolutionCallback' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-_triggerInjectionResolutionCallback' class='name expandable'>_triggerInjectionResolutionCallback</a>( <span class='pre'>Object injectionResolvedValue, Function callback, [Object context], [Boolean forceAsync]</span> )<strong class='private signature' >private</strong></div><div class='description'><div class='short'>an Error will be thrown if the callback function have more than 1 arg and none of them is called \"injectionName\" ...</div><div class='long'><p>an Error will be thrown if the callback function have more than 1 arg and none of them is called \"injectionName\"</p>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>injectionResolvedValue</span> : Object<div class='sub-desc'>\n</div></li><li><span class='pre'>callback</span> : Function<div class='sub-desc'>\n</div></li><li><span class='pre'>context</span> : Object (optional)<div class='sub-desc'>\n<p>Defaults to: <code>null</code></p></div></li><li><span class='pre'>forceAsync</span> : Boolean (optional)<div class='sub-desc'>\n<p>Defaults to: <code>false</code></p></div></li></ul><h3 class='pa'>Throws</h3><ul><li><span class='pre'>Error</span><div class='sub-desc'><p>an Error will be thrown if the callback function have more than 1 arg and none of them is called \"injectionName\"</p>\n</div></li></ul></div></div></div><div id='method-asSingleton' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-asSingleton' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-asSingleton' class='name expandable'>asSingleton</a>( <span class='pre'></span> ) : <a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></div><div class='description'><div class='short'>When this method is called on an Injection Mapping, its resolution will be triggered the first time it is\nrequested, ...</div><div class='long'><p>When this method is called on an Injection Mapping, its resolution will be triggered the first time it is\nrequested, but any subsequent call will use this first-time resolved value.</p>\n<h3 class='pa'>Returns</h3><ul><li><span class='pre'><a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></span><div class='sub-desc'><p>The <code>InjectionMapping</code> the method is invoked on</p>\n</div></li></ul><h3 class='pa'>Throws</h3><ul><li><span class='pre'>Error</span><div class='sub-desc'>\n</div></li></ul></div></div></div><div id='method-isSealed' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-isSealed' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-isSealed' class='name expandable'>isSealed</a>( <span class='pre'></span> ) : Boolean</div><div class='description'><div class='short'>If the seal method has been called on this InjectionMapping, returns true ...</div><div class='long'><p>If the <a href=\"#!/api/InjectionMapping-method-seal\" rel=\"InjectionMapping-method-seal\" class=\"docClass\">seal</a> method has been called on this InjectionMapping, returns <code>true</code></p>\n<h3 class='pa'>Returns</h3><ul><li><span class='pre'>Boolean</span><div class='sub-desc'>\n</div></li></ul></div></div></div><div id='method-resolveInjection' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-resolveInjection' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-resolveInjection' class='name expandable'>resolveInjection</a>( <span class='pre'>Function callback, [Object context], [Boolean forceAsync]</span> )</div><div class='description'><div class='short'>Resolves the injection mapping. ...</div><div class='long'><p>Resolves the injection mapping.\nWhen it's resolved, the callback function is triggered in the supplied context.\nThe first arg of the triggered callback will be the injection value. If you have anothers\nargs in the callback function, they will be inspected and may be filled with other injections values too,\nfor each of these function arg whose name s the same that an existing InjectionMapping.</p>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>callback</span> : Function<div class='sub-desc'>\n</div></li><li><span class='pre'>context</span> : Object (optional)<div class='sub-desc'>\n<p>Defaults to: <code>null</code></p></div></li><li><span class='pre'>forceAsync</span> : Boolean (optional)<div class='sub-desc'>\n<p>Defaults to: <code>false</code></p></div></li></ul></div></div></div><div id='method-seal' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-seal' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-seal' class='name expandable'>seal</a>( <span class='pre'></span> ) : Object</div><div class='description'><div class='short'>Seal this Injection mapping. ...</div><div class='long'><p>Seal this Injection mapping. Any subsequent call to any of the</p>\n\n<h1>toValue, \"toProvider()\", \"toModule\" or \"asSingleton()\" methods will throw</h1>\n\n<p>an Error. @see <a href=\"#!/api/InjectionMapping-method-unseal\" rel=\"InjectionMapping-method-unseal\" class=\"docClass\">unseal</a>()</p>\n<h3 class='pa'>Returns</h3><ul><li><span class='pre'>Object</span><div class='sub-desc'><p>returns a \"unseal\" key ; the only way to unseal this InjectionMapping it to call its \"unseal()\" method with this key</p>\n</div></li></ul><h3 class='pa'>Throws</h3><ul><li><span class='pre'>Error</span><div class='sub-desc'><p>@see <a href=\"#!/api/InjectionMapping-method-unseal\" rel=\"InjectionMapping-method-unseal\" class=\"docClass\">unseal</a>()</p>\n</div></li></ul></div></div></div><div id='method-toModule' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-toModule' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-toModule' class='name expandable'>toModule</a>( <span class='pre'>String modulePathToRequire, [String targetModulePropertyName]</span> ) : <a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></div><div class='description'><div class='short'>Maps an injection value to the result of a module. ...</div><div class='long'><p>Maps an injection value to the result of a module.\nUse this only in Node.js or AMD environments (needs the presence of a global \"require\" function).\n@see https://github.com/amdjs/amdjs-api/wiki/AMD</p>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>modulePathToRequire</span> : String<div class='sub-desc'>\n</div></li><li><span class='pre'>targetModulePropertyName</span> : String (optional)<div class='sub-desc'>\n<p>Defaults to: <code>null</code></p></div></li></ul><h3 class='pa'>Returns</h3><ul><li><span class='pre'><a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></span><div class='sub-desc'><p>The <code>InjectionMapping</code> the method is invoked on</p>\n</div></li></ul><h3 class='pa'>Throws</h3><ul><li><span class='pre'>Error</span><div class='sub-desc'>\n</div></li></ul></div></div></div><div id='method-toProvider' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-toProvider' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-toProvider' class='name expandable'>toProvider</a>( <span class='pre'>Function injectionValueProviderFunction</span> ) : <a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></div><div class='description'><div class='short'>The Injection Mapping value will be resolved through a Provider function. ...</div><div class='long'><p>The Injection Mapping value will be resolved through a Provider function.\nIf this function has a \"callback\" argument, it will be considered as an asynchronous Provider.</p>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>injectionValueProviderFunction</span> : Function<div class='sub-desc'>\n</div></li></ul><h3 class='pa'>Returns</h3><ul><li><span class='pre'><a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></span><div class='sub-desc'><p>The <code>InjectionMapping</code> the method is invoked on</p>\n</div></li></ul><h3 class='pa'>Throws</h3><ul><li><span class='pre'>Error</span><div class='sub-desc'>\n</div></li></ul></div></div></div><div id='method-toType' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-toType' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-toType' class='name expandable'>toType</a>( <span class='pre'>Function javascriptType</span> ) : <a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></div><div class='description'><div class='short'>Each time this Injection Mapping value will be requested, a new instance of the target Javascript type will\nbe created. ...</div><div class='long'><p>Each time this Injection Mapping value will be requested, a new instance of the target Javascript type will\nbe created.\nUse it with <a href=\"#!/api/InjectionMapping-method-asSingleton\" rel=\"InjectionMapping-method-asSingleton\" class=\"docClass\">asSingleton</a>() to map a lazy-loaded shared instance to this Injection Mapping.</p>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>javascriptType</span> : Function<div class='sub-desc'>\n</div></li></ul><h3 class='pa'>Returns</h3><ul><li><span class='pre'><a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></span><div class='sub-desc'><p>The <code>InjectionMapping</code> the method is invoked on</p>\n</div></li></ul><h3 class='pa'>Throws</h3><ul><li><span class='pre'>Error</span><div class='sub-desc'>\n</div></li></ul></div></div></div><div id='method-toValue' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-toValue' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-toValue' class='name expandable'>toValue</a>( <span class='pre'>Object value</span> ) : <a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></div><div class='description'><div class='short'>The simplest Injection Mapping type : each time a component will request this Injection Mapping injection, the\ntarget...</div><div class='long'><p>The simplest Injection Mapping type : each time a component will request this Injection Mapping injection, the\ntarget value will be injected.\nSince this value is a plain Javascript scalar, Array or Object, it's shared in all the application and calling</p>\n\n<h1>asSingleton on such an Injection Mapping is useless.</h1>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>value</span> : Object<div class='sub-desc'>\n</div></li></ul><h3 class='pa'>Returns</h3><ul><li><span class='pre'><a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></span><div class='sub-desc'><p>The <code>InjectionMapping</code> the method is invoked on</p>\n</div></li></ul><h3 class='pa'>Throws</h3><ul><li><span class='pre'>Error</span><div class='sub-desc'>\n</div></li></ul></div></div></div><div id='method-unseal' class='member not-inherited'><a href='#' class='side expandable'><span>&nbsp;</span></a><div class='title'><div class='meta'><span class='defined-in' rel='InjectionMapping'>InjectionMapping</span><br/><a href='source/medic-injector.html#InjectionMapping-method-unseal' target='_blank' class='view-source'>view source</a></div><a href='#!/api/InjectionMapping-method-unseal' class='name expandable'>unseal</a>( <span class='pre'>Object key</span> ) : <a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></div><div class='description'><div class='short'>Reverts the effect of seal, makes the mapping changeable again. ...</div><div class='long'><p>Reverts the effect of <code>seal</code>, makes the mapping changeable again. Has to be invoked with the unique key object returned by an earlier call to <code>seal</code> Can't unseal a mapping that's not sealed\n@see <a href=\"#!/api/InjectionMapping-method-seal\" rel=\"InjectionMapping-method-seal\" class=\"docClass\">seal</a>()</p>\n<h3 class=\"pa\">Parameters</h3><ul><li><span class='pre'>key</span> : Object<div class='sub-desc'><p>The key to unseal the mapping. Has to be the instance returned by\n<code>seal()</code></p>\n</div></li></ul><h3 class='pa'>Returns</h3><ul><li><span class='pre'><a href=\"#!/api/InjectionMapping\" rel=\"InjectionMapping\" class=\"docClass\">InjectionMapping</a></span><div class='sub-desc'><p>The <code>InjectionMapping</code> the method is invoked on</p>\n</div></li></ul><h3 class='pa'>Throws</h3><ul><li><span class='pre'>Error</span><div class='sub-desc'><p>Has to be invoked with the unique key object returned by an earlier call to <code>seal</code></p>\n</div></li><li><span class='pre'>Error</span><div class='sub-desc'><p>Can't unseal a mapping that's not sealed\n@see <a href=\"#!/api/InjectionMapping-method-seal\" rel=\"InjectionMapping-method-seal\" class=\"docClass\">seal</a>()</p>\n</div></li></ul></div></div></div></div></div></div></div>","override":null,"extends":null,"html_meta":{},"uses":[],"alternateClassNames":[],"members":{"method":[{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"constructor","id":"method-constructor"},{"tagname":"method","meta":{"private":true},"owner":"InjectionMapping","name":"_onAsyncResolutionInSingletonMode","id":"method-_onAsyncResolutionInSingletonMode"},{"tagname":"method","meta":{"private":true},"owner":"InjectionMapping","name":"_resolveModule","id":"method-_resolveModule"},{"tagname":"method","meta":{"private":true},"owner":"InjectionMapping","name":"_resolveProvider","id":"method-_resolveProvider"},{"tagname":"method","meta":{"private":true},"owner":"InjectionMapping","name":"_throwSealedException","id":"method-_throwSealedException"},{"tagname":"method","meta":{"private":true},"owner":"InjectionMapping","name":"_triggerFunction","id":"method-_triggerFunction"},{"tagname":"method","meta":{"private":true},"owner":"InjectionMapping","name":"_triggerInjectionResolutionCallback","id":"method-_triggerInjectionResolutionCallback"},{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"asSingleton","id":"method-asSingleton"},{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"isSealed","id":"method-isSealed"},{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"resolveInjection","id":"method-resolveInjection"},{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"seal","id":"method-seal"},{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"toModule","id":"method-toModule"},{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"toProvider","id":"method-toProvider"},{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"toType","id":"method-toType"},{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"toValue","id":"method-toValue"},{"tagname":"method","meta":{},"owner":"InjectionMapping","name":"unseal","id":"method-unseal"}],"cfg":[],"property":[{"tagname":"property","meta":{},"owner":"InjectionMapping","name":"injectionName","id":"property-injectionName"}],"css_var":[],"event":[],"css_mixin":[]},"subclasses":[],"superclasses":[],"singleton":false,"tagname":"class","statics":{"method":[],"cfg":[],"property":[],"css_var":[],"event":[],"css_mixin":[]},"requires":[],"mixins":[],"private":null,"component":false,"meta":{},"name":"InjectionMapping","linenr":17,"files":[{"href":"medic-injector.html#InjectionMapping","filename":"medic-injector.js"},{"href":"medic-injector.html#InjectionMapping","filename":"medic-injector.js"},{"href":"medic-injector.sync.html#InjectionMapping","filename":"medic-injector.sync.js"}],"inheritdoc":null,"enum":null,"id":"class-InjectionMapping","mixedInto":[],"aliases":{}});
View
479 medic-injector.sync.js
@@ -0,0 +1,479 @@
+/*
+ * This file is part of the Medic-Injector library.
+ *
+ * (c) Olivier Philippon <https://github.com/DrBenton>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * Strongly inspired by the SwiftSuspenders (https://github.com/tschneidereit/SwiftSuspenders)
+ * ActionScript 3 library.
+ */
+
+(function(context) {
+
+ var myDebug = false;
+
+ /**
+ * @class InjectionMapping
+ */
+
+ var FORBIDDEN_INJECTIONS_NAMES = [
+ 'injectionValue'
+ ];
+
+ /**
+ * You cant' use this constructor directly. Use Injector.addMapping to create a new "synchronous operations only"
+ * Injection Mapping.
+ *
+ * @class sync.InjectionMapping
+ * @constructor
+ * @param {sync.Injector} injectorInstance
+ * @param {String} injectionName
+ * @return {sync.InjectionMapping}
+ */
+ var InjectionMapping = function (injectorInstance, injectionName)
+ {
+ if (! (injectorInstance instanceof Injector)) {
+ throw new Error('Don\'t instantiate InjectionMapping directly ; use Injector#addMapping to create InjectionMappings!');
+ }
+ if (-1 < FORBIDDEN_INJECTIONS_NAMES.indexOf(injectionName)) {
+ throw new Error('Injection name "'+injectionName+'" is forbidden');
+ }
+ this._injector = injectorInstance;
+ /**
+ *
+ * @type {String}
+ */
+ this.injectionName = injectionName;
+ };
+
+ /**
+ * The simplest Injection Mapping type : each time a component will request this Injection Mapping injection, the
+ * target value will be injected.
+ * Since this value is a plain Javascript scalar, Array or Object, it's shared in all the application and calling
+ * #asSingleton on such an Injection Mapping is useless.
+ *
+ * @param value
+ * @return {sync.InjectionMapping} The <code>InjectionMapping</code> the method is invoked on
+ * @throws {Error}
+ */
+ InjectionMapping.prototype.toValue = function (value)
+ {
+ this._sealed && this._throwSealedException();
+ this._toValue = value;
+ return this;
+ };
+
+ /**
+ * The Injection Mapping value will be resolved through a Provider function.
+ *
+ * @param {Function} injectionValueProviderFunction
+ * @return {sync.InjectionMapping} The <code>InjectionMapping</code> the method is invoked on
+ * @throws {Error}
+ */
+ InjectionMapping.prototype.toProvider = function (injectionValueProviderFunction)
+ {
+ this._sealed && this._throwSealedException();
+ this._toProvider = injectionValueProviderFunction;
+ return this;
+ };
+
+ /**
+ * Each time this Injection Mapping value will be requested, a new instance of the target Javascript type will
+ * be created.
+ * Use it with #asSingleton() to map a lazy-loaded shared instance to this Injection Mapping.
+ *
+ * @param {Function} javascriptType
+ * @return {sync.InjectionMapping} The <code>InjectionMapping</code> the method is invoked on
+ * @throws {Error}
+ */
+ InjectionMapping.prototype.toType = function (javascriptType)
+ {
+ this._sealed && this._throwSealedException();
+ if (!(javascriptType instanceof Function))
+ {
+ throw new Error('InjectionMapping.toType() argument must be a Javascript type (i.e. a function instantiable with "new")')
+ }
+ this._toType = javascriptType;
+ return this;
+ };
+
+ /**
+ * When this method is called on an Injection Mapping, its resolution will be triggered the first time it is
+ * requested, but any subsequent call will use this first-time resolved value.
+ *
+ * @return {sync.InjectionMapping} The <code>InjectionMapping</code> the method is invoked on
+ * @throws {Error}
+ */
+ InjectionMapping.prototype.asSingleton = function ()
+ {
+ this._sealed && this._throwSealedException();
+ this._asSingleton = true;
+ return this;
+ };
+
+ /**
+ * Resolves the injection mapping.
+ *
+ * @return the Injection Mapping resolved value
+ */
+ InjectionMapping.prototype.resolveInjection = function ()
+ {
+ var returnedValue = null;
+
+ if (this._singletonValue) {
+
+ returnedValue = this._singletonValue;
+
+ } else if (this._toValue) {
+
+ returnedValue = this._toValue;
+
+ } else if (this._toType) {
+
+ returnedValue = new this._toType();
+
+ } else if (this._toProvider) {
+
+ // The Provider function may itself ask for other injections.
+ returnedValue = this._injector.triggerFunctionWithInjectedParams(this._toProvider);
+
+ }
+
+ if (this._asSingleton) {
+ this._singletonValue = returnedValue;//we won't ask for resolution again
+ }
+
+ return returnedValue;
+ };
+
+ /**
+ * Seal this Injection mapping. Any subsequent call to any of the
+ * #toValue, "toProvider()" or "asSingleton()" methods will throw
+ * an Error.
+ *
+ * @return {Object} returns a "unseal" key ; the only way to unseal this InjectionMapping it to call its "unseal()" method with this key
+ * @throws {Error}
+ * @see #unseal()
+ */
+ InjectionMapping.prototype.seal = function ()
+ {
+ this._sealed && this._throwSealedException();
+ this._sealed = true;
+ this._sealKey = {};
+ return this._sealKey;
+ };
+
+ /**
+ * Reverts the effect of <code>seal</code>, makes the mapping changeable again.
+ *
+ * @param {Object} key The key to unseal the mapping. Has to be the instance returned by
+ * <code>seal()</code>
+ * @return {sync.InjectionMapping} The <code>InjectionMapping</code> the method is invoked on
+ * @throws {Error} Has to be invoked with the unique key object returned by an earlier call to <code>seal</code>
+ * @throws {Error} Can't unseal a mapping that's not sealed
+ * @see #seal()
+ */
+ InjectionMapping.prototype.unseal = function (key)
+ {
+ if (!this._sealed) {
+ throw new Error('Can\'t unseal a non-sealed mapping.');
+ }
+ if (key !== this._sealKey)
+ {
+ throw new InjectorError('Can\'t unseal mapping without the correct key.');
+ }
+ this._sealed = false;
+ this._sealKey = null;
+ return this;
+ };
+
+ /**
+ * If the #seal method has been called on this InjectionMapping, returns `true`
+ * @return {Boolean}
+ */
+ InjectionMapping.prototype.isSealed = function ()
+ {
+ return this._sealed;
+ };
+
+ /**
+ *
+ * @private
+ */
+ InjectionMapping.prototype._throwSealedException = function ()
+ {
+ throw new Error('Modifications on a sealed InjectionMapping is forbidden!');
+ };
+
+ // Injector
+ /**
+ * Creates a new "synchronous operations only" Injector instance.
+ *
+ * @class sync.Injector
+ * @constructor
+ * @return {sync.Injector}
+ */
+ var Injector = function ()
+ {
+ this._mappings = {};
+ return this;
+ };
+
+ /**
+ * The name of the function to trigger in a custom JS type instance after the resolution of all its Injections Points.
+ * @property {String}
+ */
+ Injector.prototype.instancePostInjectionsCallbackName = 'postInjections';
+
+ /**
+ * Adds a new InjectionMapping to the Injector.
+ *
+ * @param {String} injectionName
+ * @return {sync.InjectionMapping}
+ */
+ Injector.prototype.addMapping = function (injectionName)
+ {
+ if (!!this._mappings[injectionName]) {
+ throw new Error('Injection name "'+injectionName+'" is already used!');
+ }
+ var newInjectionMapping = new InjectionMapping(this, injectionName);
+ this._mappings[injectionName] = newInjectionMapping;
+ return newInjectionMapping;
+ };
+
+ /**
+ * Removes an existing InjectionMapping.
+ *
+ * @param {String} injectionName
+ * @return {sync.Injector}
+ * @throws {Error} An Error is thrown if the target InjectionMapping has been sealed
+ */
+ Injector.prototype.removeMapping = function (injectionName)
+ {
+ if (!!this._mappings[injectionName] && this._mappings[injectionName].isSealed()) {
+ throw new Error('Injection name "'+injectionName+'" is sealed and cannot be removed!');
+ }
+ delete this._mappings[injectionName];
+ return this;
+ };
+
+ /**
+ *
+ * @param {String} injectionName
+ * @return {Boolean}
+ */
+ Injector.prototype.hasMapping = function (injectionName)
+ {
+ return !!this._mappings[injectionName];
+ };
+
+ /**
+ *
+ * @param {String} injectionName
+ * @return {sync.InjectionMapping}
+ */
+ Injector.prototype.getMapping = function (injectionName)
+ {
+ return this._mappings[injectionName] || null;
+ };
+
+ /**
+ * Triggers the target function with the supplied context.
+ * The function args are parsed, and for each of these args whose name equals a registered InjectionMapping name
+ * the injection will be resolved and its value will fill the matching function arg value.
+ *
+ * @param {Function} func
+ * @param {Object} [context=null]
+ * @return the function returned value
+ */
+ Injector.prototype.triggerFunctionWithInjectedParams = function (func, context)
+ {
+ myDebug && console && console.log('triggerFunctionWithInjectedParams() ; func=', func);
+ var functionArgsNames = getArgumentNames(func);
+ var resolvedInjectionsValues = this.resolveInjections(functionArgsNames);
+ return func.apply(context, resolvedInjectionsValues);
+ };
+
+
+ /**
+ *
+ * @param {Object} jsTypeInstance
+ * @param {Boolean} [proceedToInjectionsInPostInjectionsMethodToo=false]
+ */
+ Injector.prototype.injectInto = function (jsTypeInstance, proceedToInjectionsInPostInjectionsMethodToo)
+ {
+ // Let's scan this JS object instance for injection points...
+ var propsToInject = [];
+ for (var propName in jsTypeInstance) {
+ if (null === jsTypeInstance[propName] && !!this._mappings[propName]) {
+ // This instance property is null and its name matches a registered injection name
+ // --> let's handle it as an injection point!
+ propsToInject.push(propName);
+ }
+ }
+
+ var resolvedInjectionsValues = this.resolveInjections(propsToInject);
+
+ for (var i = 0; i < resolvedInjectionsValues.length; i++) {
+ var propName = propsToInject[i]
+ , propValue = resolvedInjectionsValues[i];
+ jsTypeInstance[propName] = propValue;//property injection!
+ }
+
+ // Okay, now we may trigger the JS object instance "postInjection" method if it has one...
+ if (!!jsTypeInstance[this.instancePostInjectionsCallbackName] && (jsTypeInstance[this.instancePostInjectionsCallbackName] instanceof Function)) {
+ if (!proceedToInjectionsInPostInjectionsMethodToo) {
+ // Simple "postInjection" trigger
+ jsTypeInstance[this.instancePostInjectionsCallbackName].apply(jsTypeInstance);
+ } else {
+ // We will look for injections in the "postInjection" method too!
+ this.triggerFunctionWithInjectedParams(jsTypeInstance[this.instancePostInjectionsCallbackName], jsTypeInstance);
+ }
+ }
+ };
+
+ /**
+ *
+ * @param {Function} jsType
+ * @param {Boolean} [proceedToInjectionsInPostInjectionsMethodToo=false]
+ * @return a new instance of the given type, with its Injection Points resolved and its "post injections" callback triggered
+ */
+ Injector.prototype.createInjectedInstance = function (jsType, proceedToInjectionsInPostInjectionsMethodToo)
+ {
+ var newInstance = new jsType();
+ this.injectInto(newInstance, proceedToInjectionsInPostInjectionsMethodToo);
+ return newInstance;
+ };
+
+ /**
+ * Replaces all "${injectionName}" patterns in the given String with the values of the matching Injections Mappings.
+ * For each `null` injection mapping value, an empty string is used instead of 'null'.
+ *
+ * @param {String} str
+ * @return {String}
+ */
+ Injector.prototype.parseStr = function (str)
+ {
+ var requestedInjectionsNames = [];
+ str.replace(/\$\{([a-z0-9_]+)\}/ig, bind(function (fullStr, injectionName) {
+ if (!!this._mappings[injectionName]) {
+ requestedInjectionsNames.push(injectionName);
+ }
+ return fullStr;//don't replace anything for the moment...
+ }, this));
+
+
+ var resolvedInjectionsValues = this.resolveInjections(requestedInjectionsNames);
+ for (var i = 0; i < requestedInjectionsNames.length; i++) {
+ var injectionName = requestedInjectionsNames[i]
+ , injectionValue = (null === resolvedInjectionsValues[i]) ? '' : resolvedInjectionsValues[i] ;
+ str = str.replace('${' + injectionName + '}', injectionValue);
+ }
+
+ return str;
+ };
+
+ /**
+ * Set the value of all public properties of the target JS object whose name is an injection mapping to "null".
+ * This lets you cancel the effect of #injectInto for clean garbage collection.
+ *
+ * @param {Object} jsTypeInstance
+ */
+ Injector.prototype.cancelInjectionsInto = function (jsTypeInstance)
+ {
+ // Let's scan this JS object instance for injection points...
+ for (var propName in jsTypeInstance) {
+ if (!!this._mappings[propName]) {
+ // This instance property's name matches a registered injection name
+ // --> let's cancel this injection point
+ jsTypeInstance[propName] = null;
+ }
+ }
+ };
+
+ /**
+ *
+ * @param {Array} injectionsNamesArray an Array of Strings
+ * @return {Array} an Array of resolved Injections Mappings values
+ */
+ Injector.prototype.resolveInjections = function (injectionsNamesArray)
+ {
+ myDebug && console && console.log('resolveInjections() ; injectionsNamesArray=', injectionsNamesArray);
+ var resolvedInjectionPoints = [];
+
+ for (var i = 0; i < injectionsNamesArray.length; i++ ) {
+
+ var currentInjectionName = injectionsNamesArray[i];
+
+ if (!this._mappings[currentInjectionName]) {
+ // We have no mapping for this arg : we'll send `null` to the function for this arg
+ resolvedInjectionPoints.push(null);
+ } else {
+ // We resolve the mapping
+ resolvedInjectionPoints.push(this._mappings[currentInjectionName].resolveInjection());
+ }
+
+ }
+
+ return resolvedInjectionPoints;
+ };
+
+
+ // Library export
+
+ if (typeof exports !== 'undefined') {
+ if (typeof module !== 'undefined' && module.exports) {
+ exports = module.exports = Injector;
+ }
+ exports.MedicInjector = Injector;
+ } else if (typeof define === "function" && define.amd) {
+ define('medic-injector-sync', [], function () { return Injector; } );
+ } else {
+ context['MedicInjectorSync'] = Injector;
+ }
+
+
+ // Utils
+ // Function reflection
+ /**
+ * From Prototype library
+ * @see https://github.com/sstephenson/prototype/blob/master/src/prototype/lang/function.js
+ *
+ * Prototype JavaScript framework
+ * (c) 2005-2010 Sam Stephenson
+ *
+ * Prototype is freely distributable under the terms of an MIT-style license.
+ * For details, see the Prototype web site: http://www.prototypejs.org/
+ *
+ * @param {Function} fun
+ * @return {Array}
+ * @private
+ */
+ var getArgumentNames = function (fun)
+ {
+ var names = fun.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1]
+ .replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '')
+ .replace(/\s+/g, '').split(',');
+ return names.length == 1 && !names[0] ? [] : names;
+ };
+
+ // Functions scope binding
+ /**
+ *
+ * @param {Function} func
+ * @param {Object} context
+ * @return {Function}
+ * @private
+ */
+ var bind = function (func, context)
+ {
+ var args = Array.prototype.slice.call(arguments, 2);
+ return function(){
+ return func.apply(context, args.concat(Array.prototype.slice.call(arguments)));
+ };
+ };
+
+
+})(this);
View
2  package.json
@@ -22,7 +22,7 @@
"optionalDependencies": {
},
"scripts": {
- "test": "mocha test/test.js"
+ "test": "mocha test/"
},
"keywords": [
"dependency", "injection", "injector"
View
3  test/test.js → test/medic-injector.js
@@ -2,8 +2,7 @@
var assert = require('assert');
var InjectorLib = require('../medic-injector')
- , Injector = InjectorLib.MedicInjector
- , InjectionMapping = InjectorLib.MedicInjectionMapping;
+ , Injector = InjectorLib.MedicInjector;
describe('InjectionMapping', function(){
View
416 test/medic-injector.sync.js
@@ -0,0 +1,416 @@
+
+var assert = require('assert');
+
+var InjectorLib = require('../medic-injector.sync')
+ , Injector = InjectorLib.MedicInjector;
+
+describe('InjectionMapping', function(){
+
+ describe('#toValue()', function(){
+ it('should return the value', function(){
+ var injector = new Injector();
+ var injectionMapping = injector.addMapping('test').toValue(10);
+ var injectionValue = injectionMapping.resolveInjection();
+ assert.strictEqual(10, injectionValue);
+ });
+ });// end "#toValue()" tests
+
+ describe('no resolution scheme', function(){
+ it('should return `null`', function(){
+ var injector = new Injector();
+ var injectionMapping = injector.addMapping('test');
+ var injectionValue = injectionMapping.resolveInjection();
+ assert.strictEqual(null, injectionValue);
+ });
+ });// end "no resolution scheme" tests
+
+ describe('#toProvider()', function(){
+ it('should return the Provider returned value', function(){
+ var injector = new Injector();
+ var counter = 0;
+ var injectionMapping = injector.addMapping('test').toProvider(function() {
+ counter++;
+ return 10;
+ });
+ var injectionValue = injectionMapping.resolveInjection();
+ assert.strictEqual(10, injectionValue);
+ assert.strictEqual(1, counter);
+ });
+ it('should received injected args too', function(){
+ var injector = new Injector();
+ var counter = 0;
+ injector.addMapping('injection1').toValue(-10);
+ injector.addMapping('injection2').toValue(-20);
+ var injectionMapping = injector.addMapping('test').toProvider(function(injection1, dummy1, injection2, dummy2) {
+ counter++;
+ assert.strictEqual(-10, injection1);
+ assert.strictEqual(null, dummy1);
+ assert.strictEqual(-20, injection2);
+ assert.strictEqual(null, dummy2);
+ return 10;
+ });
+ var injectionValue = injectionMapping.resolveInjection();
+ assert.strictEqual(10, injectionValue);
+ assert.strictEqual(1, counter);
+ });
+ it('should trigger the Provider function multiple times for multiple Injections resolutions requests', function(){
+ var injector = new Injector();
+ var counter = 0;
+ var injectionMapping = injector.addMapping('test').toProvider(function() {
+ counter++;
+ return 10;
+ });
+ var injectionValue = injectionMapping.resolveInjection();
+ assert.strictEqual(10, injectionValue);
+ assert.strictEqual(1, counter);
+ var injectionValue = injectionMapping.resolveInjection();
+ assert.strictEqual(10, injectionValue);
+ assert.strictEqual(2, counter);
+ });
+ });// end "#toProvider()" tests
+
+ describe('#asSingleton()', function(){
+ it('should normally return the value when used with #toValue', function(){
+ var injector = new Injector();
+ var injectionMapping = injector.addMapping('test').toValue(10).asSingleton();
+ var injectionValue = injectionMapping.resolveInjection();
+ assert.strictEqual(10, injectionValue);
+ var injectionValue = injectionMapping.resolveInjection();
+ assert.strictEqual(10, injectionValue);
+ });
+ it('should return the *same* value with only one Provider trigger when a Provider result is used multiple times', function(){
+ var injector = new Injector();
+ var counter = 0;
+ var injectionMapping = injector.addMapping('test')
+ .toProvider(function() {
+ counter++;
+ return 10;
+ })
+ .asSingleton();
+ var injectionValue = injectionMapping.resolveInjection();
+ assert.strictEqual(10, injectionValue);
+ assert.strictEqual(1, counter);
+ var injectionValue = injectionMapping.resolveInjection();
+ assert.strictEqual(10, injectionValue);
+ assert.strictEqual(1, counter);//the counter stays at "1", because the Provider is triggered only once
+ });
+ })// end "#asSingleton()" tests
+
+ describe('#toType()', function(){
+
+ var JsType = function()
+ {
+ this.counter = ++JsType._instanceCounter;
+ };
+ JsType._instanceCounter = 0;
+
+ it('should return a new instance of the given JS type', function(){
+ var injector = new Injector();
+ JsType._instanceCounter = 0;
+ var injectionMapping = injector.addMapping('test').toType(JsType);
+ var injectionValue = injectionMapping.resolveInjection();
+ assert(injectionValue instanceof JsType);
+ assert.strictEqual(1, injectionValue.counter);
+ var injectionValue = injectionMapping.resolveInjection();
+ assert(injectionValue instanceof JsType);
+ assert.strictEqual(2, injectionValue.counter);
+ });
+ it('should return a shared lazy-loaded singleton instance of the given JS type when used with #asSingleton()', function(){
+ var injector = new Injector();
+ JsType._instanceCounter = 0;
+ var injectionMapping = injector.addMapping('test').toType(JsType).asSingleton();
+ var injectionValue;
+ injectionValue = injectionMapping.resolveInjection();
+ assert(injectionValue instanceof JsType);
+ assert.strictEqual(1, injectionValue.counter);
+ injectionValue = injectionMapping.resolveInjection();
+ assert(injectionValue instanceof JsType);
+ assert.strictEqual(1, injectionValue.counter);
+ });
+ });// end "#toType()" tests
+
+ describe('#seal()/#unseal()', function(){
+ it('should seal', function(){
+ var injector = new Injector();
+ var injectionMapping = injector.addMapping('test').toValue(10);
+ injectionMapping.seal();
+ assert(injectionMapping.isSealed());
+ assert.throws(
+ function () {
+ injector.asSingleton();
+ },
+ Error
+ );
+ assert.throws(
+ function () {
+ injector.toValue(20);
+ },
+ Error
+ );
+ assert.throws(
+ function () {
+ injector.toProvider(function() {return 30;});
+ },
+ Error
+ );
+ var injectionValue = injectionMapping.resolveInjection();
+ assert.strictEqual(injectionValue, 10);
+ });
+ it('should not unseal with an invalid key', function(){
+ var injector = new Injector();
+ var injectionMapping = injector.addMapping('test').toValue(10);
+ injectionMapping.seal();
+ assert(injectionMapping.isSealed());
+ assert.throws(
+ function () {
+ injector.unseal(null);
+ },
+ Error
+ );
+ assert.throws(
+ function () {
+ injector.unseal({});
+ },
+ Error
+ );
+ });
+ it('should successfully unseal with the seal key', function(){
+ var injector = new Injector();
+ var injectionMapping = injector.addMapping('test').toValue(10);
+ var sealKey = injectionMapping.seal();
+ assert(injectionMapping.isSealed());
+ injectionMapping.unseal(sealKey);
+ assert(!injectionMapping.isSealed());
+ });
+
+ });// end "#seal()/#unseal()" tests
+
+});//end "InjectionMapping" tests
+
+describe('Injector', function(){
+
+ describe('#triggerFunctionWithInjectedParams()', function(){
+ it('should handle a given context successfully', function(done){
+ var injector = new Injector();
+ injector.addMapping('injection1').toValue(10);
+ injector.addMapping('injection2').toProvider(function () {return 20;});
+ var targetFunctionContext = {
+ 'contextProp': -1
+ };
+ var targetFunction = function (injection1, injection2)
+ {
+ assert.strictEqual(10, injection1);
+ assert.strictEqual(20, injection2);
+ assert.strictEqual(-1, this.contextProp);
+ done();
+ };
+ injector.triggerFunctionWithInjectedParams(targetFunction, targetFunctionContext);
+ });
+ it('should be able to resolve misc injected params', function(done){
+ // We already tested each of these InjectionsMappings, we can mix them from now on
+ var injector = new Injector();
+
+ var JsType = function()
+ {
+ this.counter = ++JsType._instanceCounter;
+ };
+ JsType._instanceCounter = 0;
+
+ injector.addMapping('injection1').toValue(10);
+ injector.addMapping('injection2').toProvider(function () {return 20;});
+ injector.addMapping('injection3').toProvider(function () {
+ return 30;
+ });
+ injector.addMapping('injection4').toProvider(function (injection8) {//this provider is itself "injected"
+ assert.strictEqual(1, injection8.counter);
+ return 40;
+ });
+ injector.addMapping('injection5').toProvider(function (injection4, injection8) {//this provider is itself "injected" with the "injected" previous one
+ assert.strictEqual(2, injection8.counter);
+ return injection4+10;
+ });
+ injector.addMapping('injection6').toProvider(function (injection5, injection9) {//this provider is itself "injected" with the "injected" previous one
+ assert.strictEqual(3, injection9.counter);//injection 9 is singleton
+ return injection5+10;
+ }).asSingleton();
+ injector.addMapping('injection7').toProvider(function (injection9) {//this provider is itself "injected" with the "injected" previous one
+ assert.strictEqual(3, injection9.counter);//injection 9 is singleton
+ return 70;
+ });
+ injector.addMapping('injection8').toType(JsType);
+ injector.addMapping('injection9').toType(JsType).asSingleton();
+
+ var targetFunction = function (injection2, injection1, unmatchedInjection, injection6, injection3, injection7)
+ {
+ assert.strictEqual(10, injection1);
+ assert.strictEqual(20, injection2);
+ assert.strictEqual(30, injection3);
+ assert.strictEqual(60, injection6);
+ assert.strictEqual(70, injection7);
+ assert.strictEqual(null, unmatchedInjection);
+ done();
+ };
+
+ injector.triggerFunctionWithInjectedParams(targetFunction);
+ });
+ });// end "#triggerFunctionWithInjectedParams()" tests
+
+ describe('#removeMapping()', function(){
+ it('should remove a given mapping', function(){
+ var injector = new Injector();
+ assert(!injector.hasMapping('injection1'));
+ injector.addMapping('injection1').toValue(10);
+ assert(injector.hasMapping('injection1'));
+ injector.removeMapping('injection1');
+ assert(!injector.hasMapping('injection1'));
+ });
+ it('should not remove a sealed mapping', function(){
+ var injector = new Injector();
+ injector.addMapping('injection1').toValue(10).seal();
+ assert(injector.hasMapping('injection1'));
+ assert.throws(
+ function () {
+ injector.removeMapping('injection1');
+ },
+ Error
+ );
+ assert(injector.hasMapping('injection1'));
+ });
+ it('should remove an unsealed mapping', function(){
+ var injector = new Injector();
+ var sealKey = injector.addMapping('injection1').toValue(10).seal();
+ assert(injector.hasMapping('injection1'));
+ injector.getMapping('injection1').unseal(sealKey);
+ injector.removeMapping('injection1');
+ assert(!injector.hasMapping('injection1'));
+ });
+ });// end "#removeMapping()" tests
+
+ describe('#injectInto()', function(){
+ it('should inject a simple "null" injection point, and ignore other properties', function(){
+ var injector = new Injector();
+ var JsType = function()
+ {
+ this.injection1 = null;
+ this.injection2 = 'not null';
+ this.injection3 = null;
+ };
+ injector.addMapping('injection1').toValue(10);
+ injector.addMapping('injection2').toValue(20);
+ var jsTypeInstance = new JsType();
+ injector.injectInto(jsTypeInstance);
+ assert.strictEqual(10, jsTypeInstance.injection1);
+ assert.strictEqual('not null', jsTypeInstance.injection2);
+ assert.strictEqual(null, jsTypeInstance.injection3);
+ });
+ it('should trigger the given callback after injection', function(){
+ var injector = new Injector();
+ var JsType = function()
+ {
+ this.injection1 = null;
+ this.injection2 = null;
+ };
+ var counter = 0;
+ injector.addMapping('injection1').toValue(10);
+ var jsTypeInstance = new JsType();
+ injector.injectInto(jsTypeInstance);
+ assert.strictEqual(10, jsTypeInstance.injection1);
+ assert.strictEqual(null, jsTypeInstance.injection2);
+ assert.strictEqual(0, counter);
+ });
+ it('should trigger the JS object "postInjections()" method after injection', function(){
+ var injector = new Injector();
+ var nbPostInjectionsTriggered = 0;
+ var JsType = function()
+ {
+ this.injection1 = null;
+ this.injection2 = null;
+ this.postInjections = function() {
+ nbPostInjectionsTriggered++;
+ };
+ this.customPostInjectionsMethod = function() {
+ nbPostInjectionsTriggered++;
+ };
+ };
+ injector.addMapping('injection1').toValue(10);
+ var jsTypeInstance = new JsType();
+ injector.injectInto(jsTypeInstance);
+ assert.strictEqual(10, jsTypeInstance.injection1);
+ assert.strictEqual(1, nbPostInjectionsTriggered);
+ });
+ it('should trigger the JS object custom "postInjections()" method after injection', function(){
+ var injector = new Injector();
+ injector.instancePostInjectionsCallbackName = 'customPostInjectionsMethod';
+ var nbPostInjectionsTriggered = 0;
+ var JsType = function()
+ {
+ this.injection1 = null;
+ this.injection2 = null;
+ this.customPostInjectionsMethod = function() {
+ assert.strictEqual(1, ++nbPostInjectionsTriggered);
+ };
+ };
+ injector.addMapping('injection1').toValue(10);
+ var jsTypeInstance = new JsType();
+ injector.injectInto(jsTypeInstance);
+ assert.strictEqual(10, jsTypeInstance.injection1);
+ assert.strictEqual(2, ++nbPostInjectionsTriggered);
+ });
+ it('should proceed to injections in the "postInjections()" method after injection, if asked', function(done){
+ var injector = new Injector();
+ var JsType = function()
+ {
+ this.injection1 = null;
+ this.postInjections = function(injection1, injection2) {
+ assert.strictEqual(10, this.injection1);
+ assert.strictEqual(10, injection1);
+ assert.strictEqual(20, injection2);
+ done();
+ };
+ };
+ injector.addMapping('injection1').toValue(10);
+ injector.addMapping('injection2').toProvider(function() {
+ return 20;
+ });
+ var jsTypeInstance = new JsType();
+ injector.injectInto(jsTypeInstance, true);//we enable the "proceedToInjectionsInPostInjectionsMethodToo" flag
+ });
+ });// end "#injectInto()" tests
+
+ describe('#createInjectedInstance()', function(){
+ it('should give a fully "injected" object instance', function(){
+ var injector = new Injector();
+ var JsType = function()
+ {
+ this.injection1 = null;
+ this.customValueFromPostInjectionsMethod = null;
+ this.postInjections = function(injection2) {
+ this.customValueFromPostInjectionsMethod = injection2;
+ };
+ };
+ injector.addMapping('injection1').toValue(10);
+ injector.addMapping('injection2').toProvider(function() {
+ return 20;
+ });
+ var jsTypeInstance = injector.createInjectedInstance(JsType, true);//we enable the "proceedToInjectionsInPostInjectionsMethodToo" flag
+ assert(jsTypeInstance instanceof JsType);
+ assert.strictEqual(10, jsTypeInstance.injection1);
+ assert.strictEqual(20, jsTypeInstance.customValueFromPostInjectionsMethod);
+ });
+ });// end "#createInjectedInstance()" tests
+
+ describe('#parseStr()', function(){
+ it('should successfully replace ${injectionName} patterns', function(){
+ var injector = new Injector();
+ injector.addMapping('injection1').toValue(10);
+ injector.addMapping('injection2').toProvider(function() {
+ return 20;
+ });
+ injector.addMapping('injection3').toValue(null);
+ var sourceStr = '${injection1}::${injection2}::${injection3}';
+ var injectedStr = injector.parseStr(sourceStr);
+ assert.strictEqual('10::20::', injectedStr);
+ });
+ });// end "#parseStr()" tests
+
+});//end "Injector" tests
Please sign in to comment.
Something went wrong with that request. Please try again.