GitXplorerGitXplorer
F

xaop

public
1 stars
0 forks
0 issues

Commits

List of commits on branch master.
Verified
6289e64ec85b739e7333e47f9f5f638e4cdf2e15

Merge pull request #7 from FishOrBear/dependabot/npm_and_yarn/acorn-5.7.4

FFishOrBear committed 5 years ago
Verified
d255a853ca1f7ea33d27da40507afeca322ed248

Bump acorn from 5.7.1 to 5.7.4

ddependabot[bot] committed 5 years ago
Verified
89b35f262ebc03748671a3eb8d9ac5a444a09c69

Merge pull request #2 from FishOrBear/dependabot/npm_and_yarn/mixin-deep-1.3.2

FFishOrBear committed 5 years ago
Verified
43437f6adc920cf84732beccaf8214f7fedaaf7e

Merge pull request #3 from FishOrBear/dependabot/npm_and_yarn/lodash-4.17.15

FFishOrBear committed 5 years ago
Verified
7f7c025bb504a7ccebbf76def708f9ce99eeb84e

Merge pull request #4 from FishOrBear/dependabot/npm_and_yarn/js-yaml-3.13.1

FFishOrBear committed 5 years ago
Verified
1a87ac5f073974625468ace55f486b464d1178ad

Merge pull request #5 from FishOrBear/dependabot/npm_and_yarn/merge-1.2.1

FFishOrBear 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
*/