1.1.6 • Published 6 years ago

dependency-inject v1.1.6

Weekly downloads
46
License
ISC
Repository
github
Last release
6 years ago

DependencyInject

Live Demo

import { Container, inject } from 'dependency-inject'

class Store {
    num = 1
}

class Action {
    @inject(Store)
    private store: Store

    setNum(num: number) {
        this.store.num = num
    }
}

// init store
const container = new Container()
container.set(Store, new Store())
container.set(Action, new Action())

// get data with injected
const store = container.get(Store)
const action = container.get(Action)

action.setNum(2)
console.log(store.num) // 2

Simple useage by injectFactory

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

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
    }
})
1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago