dependency-inject
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -70,3 +70,2 @@ "use strict"; | ||
}); | ||
console.log(123, result); | ||
result.Action.setNum(2); | ||
@@ -73,0 +72,0 @@ t.true(result.group.Store.num === 2); |
@@ -46,5 +46,3 @@ "use strict"; | ||
var result = index_1.injectFactory({ | ||
group: { | ||
Store: Store | ||
}, | ||
Store: Store, | ||
Action: Action | ||
@@ -51,0 +49,0 @@ }); |
{ | ||
"name": "dependency-inject", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "built/index.js", |
@@ -33,1 +33,48 @@ # DependencyInject | ||
``` | ||
# Simple useage by injectFactory | ||
```typescript | ||
import { injectFactory } from 'dependency-inject' | ||
class Store { | ||
num = 1 | ||
} | ||
class Action { | ||
@inject(Store) | ||
private store: Store | ||
setNum(num: number) { | ||
this.store.num = num | ||
} | ||
} | ||
const stores = injectFactory({Store, Action}) | ||
// stores.Store.num === 1 | ||
// stores.Action.setNum | ||
``` | ||
## nested object | ||
```typescript | ||
import { injectFactory } from 'dependency-inject' | ||
class Store { | ||
num = 1 | ||
} | ||
class Action { | ||
@inject(Store) | ||
private store: Store | ||
setNum(num: number) { | ||
this.store.num = num | ||
} | ||
} | ||
const stores = injectFactory({ | ||
groupA: Store, | ||
groupB: { | ||
groupC: Action | ||
} | ||
}) | ||
``` |
@@ -65,6 +65,4 @@ import test from 'ava' | ||
console.log(123, result) | ||
result.Action.setNum(2) | ||
t.true(result.group.Store.num === 2) | ||
}) |
@@ -11,2 +11,6 @@ import Container from "./container" | ||
type Partial<T> = { | ||
[P in keyof T]?: T[P]; | ||
} | ||
/** | ||
@@ -16,3 +20,3 @@ * 快速实例化,key: string value: Class | ||
*/ | ||
export function injectFactory<T>(obj: ICombineActions<T>): T { | ||
export function injectFactory<T>(obj: ICombineActions<T>): Partial<T> { | ||
const container = new Container() | ||
@@ -19,0 +23,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
Sorry, the diff of this file is not supported yet
189071
79
515