injectee
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Injectee

NPM version

register a component and use it in a vendor everywhere when using typescript! 💗

Installation

npm i injectee

yarn add injectee

Usage

import { Component, Vendor, Inject } from 'injectee';

// register a component
@Component
class Dog {
    say() {
        console.log('wang wang');
    }
}

// register a vendor
@Vendor
class Person {
    // inject dog component for person instance
    @Inject
    dog: Dog;

    public getMyDog() {
        return this.dog;
    }
}

// create instances from vendor
const me = new Person();
const she = new Person();

console.log(me === she);            // false
console.log(me.dog === she.dog);    // true, dog is injected as a single instance
console.log(me.getMyDog());         // Dog {}
me.dog.say();                       // wang wang

Package Sidebar

Install

npm i injectee

Weekly Downloads

3

Version

0.0.2

License

ISC

Unpacked Size

18.6 kB

Total Files

41

Last publish

Collaborators

  • xuezi