Comparing version 1.0.0-beta.2 to 1.0.0-beta.3
@@ -1,2 +0,2 @@ | ||
var t=function(t){this.t=t};t.prototype.inSingletonScope=function(){this.t.singleton=!0};var n=function(t){this.t=t};n.prototype.to=function(n){return this.t.object=n,new t(this.t)},n.prototype.toFactory=function(n){return this.t.factory=n,new t(this.t)},n.prototype.toValue=function(t){if(void 0===t)throw"cannot bind a value of type undefined";this.t.value=t};var i=function(){this.i={},this.o=[]};i.prototype.bind=function(t){return new n(this.u(t))},i.prototype.rebind=function(t){return this.remove(t).bind(t)},i.prototype.remove=function(t){if(void 0===this.i[t.toString()])throw t.toString()+" was never bound";return delete this.i[t.toString()],this},i.prototype.get=function(t){var n=this.i[t.toString()];if(void 0===n)throw"nothing bound to "+t.toString();var i=n.object,r=n.factory,o=n.value,e=n.cache,u=n.singleton,f=function(t){return u&&void 0!==e?e:u?(n.cache=t(),n.cache):t()};if(void 0!==o)return o;if(void 0!==i)return f(function(){return new i});if(void 0!==r)return f(function(){return r()});throw"nothing is bound to "+t.toString()},i.prototype.snapshot=function(){return this.o.push(Object.assign({},this.i)),this},i.prototype.restore=function(){return this.i=this.o.pop()||this.i,this},i.prototype.u=function(t){if("object"==typeof this.i[t.toString()])throw"object can only bound once: "+t.toString();return this.i[t.toString()]={singleton:!1},this.i[t.toString()]};var r=Symbol.for("NOCACHE");exports.Container=i,exports.createDecorator=function(t){return function(n){for(var i=[],o=arguments.length-1;o-- >0;)i[o]=arguments[o+1];return function(t,n,i){return function(o,e){Object.defineProperty(o,e,{get:function(){var o=n.get(t);return i&&i.indexOf(r)&&Object.defineProperty(this,e,{value:o,enumerable:!0}),o},configurable:!0,enumerable:!0})}}(n,t,i)}},exports.NOCACHE=r; | ||
var n=function(n){this.t=n};n.prototype.inSingletonScope=function(){this.t.singleton=!0};var t=function(n){this.t=n};t.prototype.to=function(t){return this.t.object=t,new n(this.t)},t.prototype.toFactory=function(t){return this.t.factory=t,new n(this.t)},t.prototype.toValue=function(n){if(void 0===n)throw"cannot bind a value of type undefined";this.t.value=n};var i=function(){this.i=new Map,this.o=[]};i.prototype.bind=function(n){return new t(this.u(n))},i.prototype.rebind=function(n){return this.remove(n).bind(n)},i.prototype.remove=function(n){if(void 0===this.i.get(n))throw n.toString()+" was never bound";return this.i.delete(n),this},i.prototype.get=function(n){var t=this.i.get(n);if(void 0===t)throw"nothing bound to "+n.toString();var i=t.object,r=t.factory,o=t.value,u=t.cache,e=t.singleton,f=function(n){return e&&void 0!==u?u:e?(t.cache=n(),t.cache):n()};if(void 0!==o)return o;if(void 0!==i)return f(function(){return new i});if(void 0!==r)return f(function(){return r()});throw"nothing is bound to "+n.toString()},i.prototype.snapshot=function(){return this.o.push(new Map(this.i)),this},i.prototype.restore=function(){return this.i=this.o.pop()||this.i,this},i.prototype.u=function(n){if(void 0!==this.i.get(n))throw"object can only bound once: "+n.toString();var t={singleton:!1};return this.i.set(n,t),t};var r=Symbol("NOCACHE");exports.Container=i,exports.createDecorator=function(n){return function(t){for(var i=[],o=arguments.length-1;o-- >0;)i[o]=arguments[o+1];return function(n,t,i){return function(o,u){Object.defineProperty(o,u,{get:function(){var o=t.get(n);return-1===i.indexOf(r)&&Object.defineProperty(this,u,{value:o,enumerable:!0}),o},configurable:!0,enumerable:!0})}}(t,n,i)}},exports.NOCACHE=r; | ||
//# sourceMappingURL=ioc.js.map |
{ | ||
"name": "@owja/ioc", | ||
"version": "1.0.0-beta.2", | ||
"version": "1.0.0-beta.3", | ||
"description": "dependency injection for javascript", | ||
@@ -18,3 +18,3 @@ "main": "dist/ioc.js", | ||
"scripts": { | ||
"build": "(rm -r dist/* || true) && microbundle --format es,cjs && (find ./dist -name '*.test.d.ts' -type f -delete || true)", | ||
"build": "(rm -r dist/* || true) && microbundle --format es,cjs", | ||
"test": "jest", | ||
@@ -21,0 +21,0 @@ "lint": "eslint --ext .ts,.js ./", |
@@ -7,4 +7,3 @@ ![OWJA! IoC](resources/owja-ioc-logo.png) | ||
[![Build Status](https://travis-ci.org/owja/ioc.svg?branch=master)](https://travis-ci.org/owja/ioc) | ||
[![gzip size](http://img.badgesize.io/https://unpkg.com/@owja/ioc/dist/ioc.mjs?compression=gzip)](https://unpkg.com/@owja/ioc/dist/ioc.mjs) | ||
[![size](https://badgen.net/packagephobia/install/@owja/ioc)](https://unpkg.com/@owja/ioc/dist/ioc.mjs) | ||
[![size](https://img.badgesize.io/https://unpkg.com/@owja/ioc/dist/ioc.mjs.svg?compression=gzip&label=size&max=1000&softmax=800&v=1)](https://unpkg.com/@owja/ioc/dist/ioc.mjs) | ||
@@ -14,4 +13,18 @@ This library implements dependency injection for javascript. | ||
but the API should not change anymore before 1.0.0 stable release | ||
will arrived. | ||
will arrive. | ||
## Features | ||
* Similar syntax to InversifyJS | ||
* Less Features but **straight forward** | ||
* Can bind dependencies as **classes**, **factories** and **static values** | ||
* Supports binding in **singleton scope** | ||
* **Cached** - Resolves only once in each dependency requesting class by default | ||
* **Cache can switched off** directly at the inject decorator | ||
* Made with **unit testing** in mind | ||
* Supports dependency **rebinding** and container **snapshots** and **restores** | ||
* **Lightweight** - Just around **750 Byte gzip** and **650 Byte brotli** compressed | ||
* Does **NOT** need reflect-metadata which size is around 50 kb | ||
* 100% written in **Typescript** | ||
## The Container API | ||
@@ -138,2 +151,13 @@ | ||
export const TYPE = { | ||
"Service" = Symbol("Service"), | ||
// [...] | ||
} | ||
``` | ||
Symbols can be defined with `Symbol.for()` too. This way they are not unique. | ||
Remember `Symbol('foo') === Symbol('foo')` is `false` but | ||
`Symbol.for('foo') === Symbol.for('foo')` is `true` | ||
```ts | ||
export const TYPE = { | ||
"Service" = Symbol.for("Service"), | ||
@@ -144,2 +168,5 @@ // [...] | ||
> Since 1.0.0-beta.3 we use the symbol itself for indexing the dependencies. | ||
> Prior to this version we indexed the dependencies by the string of the symbol. | ||
## Usage | ||
@@ -158,4 +185,4 @@ | ||
export const TYPE = { | ||
"MyService" = Symbol.for("MyService"), | ||
"MyOtherService" = Symbol.for("MyOtherService"), | ||
"MyService" = Symbol("MyService"), | ||
"MyOtherService" = Symbol("MyOtherService"), | ||
}; | ||
@@ -162,0 +189,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44624
295