2.1.0 • Published 1 year ago
xaop v2.1.0
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
*/
2.1.0
1 year ago
2.0.0
2 years ago
1.3.3
5 years ago
1.3.2
6 years ago
1.3.1
6 years ago
1.1.9
7 years ago
1.1.8
7 years ago
1.1.7
7 years ago
1.1.6
7 years ago
1.1.5
7 years ago
1.1.4
7 years ago
1.1.2
7 years ago
1.1.1
7 years ago
1.1.0
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