npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dp-mqueue

v1.0.4

Published

javascript typescript dp uni framework queue node.js

Downloads

2

Readme

dp-ioc

简单、强大的基于TypeScript的IOC库。

一、安装 [ Installation ]

  • npm i dp-ioc

二、快速开始

import { Inject, Injectable, Provider } from "dp-ioc";

//定义一个可注入类
@Injectable()
class Person {
    name = "rajan"
    dance() {
        return  this.name + " dance";
    }
}


// 注入到其他类中
class ClassRoom {

    @Inject(Person)
    public person:Person;
}

// 使用,(通过Provider函数进行实例化 )
let classRoom = Provider<ClassRoom>(ClassRoom);
console.log(classRoom.person.name); // rajan
console.log(classRoom.person.dance); // rajan dance 

注意,使用了依赖注入的类,在应用时必须通过Provider进行实例化

三、高级用法

3.1 单例

import { Single, Injectable } from "dp-ioc";

@Single()
@Injectable()
class Person {
    name = "rajan"
    dance() {
        return  this.name + " dance";
    }
}

3.2 多层注入

import { Single, Injectable,Inject,Provider } from "dp-ioc";

@Injectable()
class Person {
    name = "rajan"
    dance() {
        return  this.name + " dance";
    }
}

@Injectable()
class ClassRoom {
    name = "room 001"
    @Inject(Person)
    person:Person
}

class School {

    @Inject(ClassRoom)
    classRoom:ClassRoom;
}

let school = Provider<School>(School);

3.3 构造传参

本库支持实例化Injectable可注入对象时,传入实例化的参数

import { Single, Injectable,Inject,Provider,Constructor } from "dp-ioc";

@Injectable()
class Person {
    name = "rajan"
    age = 0;

    //ioc 容器实例化该类时,setPersonBasicInfo方法将会被执行
    @Constructor()
    setPersonBasicInfo(name:string,age:number){
        this.name = name;
        this.age = age;
    } 

    dance() {
        return  this.name + " dance";
    }

}

//注入
class ClassRoom {
    name = "room 001"

    @Inject(Person,["小明",18])
    person:Person
}

// 实例化
let classRoom = Provider<ClassRoom>(ClassRoom);
console.log(classRoom.person.name,classRoom.person.age); // 小明 18

3.4 支持继承依赖

import { Single, Injectable,Inject,Provider,Constructor } from "dp-ioc";

@Injectable()
class Human {
    age = 0;
    name = "";
}

class Student extends Human {
    dance():string{
        return this.name + "dance";
    }
}

class classRoom {
    @Inject(Student)
    public Student: Student;
}

3.5 序列化和反序列

在实际项目开发中,某些对象可能需要序列化为字符串以便存储,传输。本库支持将序列化之后的对象还原为依赖对象。

import { Single, Injectable,Inject,Provider,Constructor } from "dp-ioc";

@Injectable()
class Person {
    age = 0;
    name = "";
    dance():string{
        return this.name + "dance";
    }
}

class ClassRoom {

    @Inject(Student)
    public Student: Student;
}

let classRoom = Provider<ClassRoom>(ClassRoom);

let classRoomStr = JSON.stringify(classRoom); // 序列化为字符串

classRoom = Provider<ClassRoom>(ClassRoom,JSON.parse(classRoomStr)); // 反序列化为依赖对象

四、支持

如果在使用过程中,遇到问题,请到github仓库反馈,仓库地址