GitXplorerGitXplorer
F

xaop

public
1 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
13aa2e3161d9e6a3a2e9f25b1293b1428e9633ca

增加手动全局注入功能

committed 2 years ago
Verified
659af2e36af2994b47b1c8b2af55636df35bffd3

Delete yarn.lock

FFishOrBear committed 3 years ago
Unverified
53b725975845b60f4cdf92c683f8bbda1d061b1a

清理

committed 3 years ago
Unverified
4058ede10715153a80209e5c3435b5c7993f62e6

2.0.0 更新类型定义

committed 3 years ago
Verified
9f35dd198f5cc2b7045499a785f2703d1547cab6

Merge pull request #8 from FishOrBear/dependabot/npm_and_yarn/lodash-4.17.19

FFishOrBear committed 4 years ago
Verified
b884d339422a97c4fa1c81b851c7359c1277ee73

Bump lodash from 4.17.15 to 4.17.19

ddependabot[bot] committed 5 years ago

README

The README file for this repository.

xaop

Typescript 的Aop实现. 有关AOP编程,其实就是在函数的运行时注入相应的代码,以达到分离实现的目的.(简单的说就是这样...)

所以现在这个库用装饰器实现了一个注入工具.可以直接通过 obj.func 直接输入起始和结束,并且可以得到参数和返回结果. 下面这个例子简单的描述了这个库的使用

##安装

npm i xaop

##升级

npm publish

##注意: 默认构造参数无法捕获初始化参数.

function add(a,b=1) //这里的b是无法捕获到的
{

}

##全局注入

class E
{
    @iaop
    exec()
    {
        console.log("hello e");
    }
}

let e = new E();
let remove1 = xaop.begin(e.exec, () =>
{
    console.log("begin");
})

let remove2 = xaop.end(e.exec, function()
{
    //如果你不使用箭头函数 你可以捕获到this.
    console.log("end");
})

e.exec();
//begin
//hello e
//end
remove1();//清除注入
remove2();//清除注入
e.exec();
//hello e

##对象注入

class E
{
    exec()
    {
        console.log("hello e");
    }
}

let e=new E()
let e2=new E();
xaop.begin(e,e.exec,()=>{
    console.log("hello begin");
})

e.exec();
/*
hello begin
hello e
*/

//不影响e2的响应
e2.exec()
/*
hello e
*/