javascript-proxy-aop
v0.0.2
Published
AOP in JS with proxies
Downloads
3
Readme
javascript-proxy-aop
Uses ES6 Proxy to instrument JS in an (unfortunately too verbose) aspect-oriented way
Install
$ npm install --save javascript-proxy-aop
Usage
const javascriptProxyAop = require('javascript-proxy-aop');
// pubSub may be any object that supports trigger
const instrument = javascriptProxyAop(pubSub);
const obj = instrument({
method: function() {},
anotherMethod: function fooBar() {}
});
obj.method(['hello', 'world']);
// => pubSub.on('onBeforeMethod', method, args) is called
// => method: 'anonymous<method>'
// => args: [['hello', 'world']]
// => pubSub.on('onAfterMethod', method, args) is called
// => method: 'anonymous<method>'
// => args: [['hello', 'world']]
// => result: undefined
obj.anotherMethod(); // method is 'fooBar'
TODO
- [ ] enable to instrument functions directly
License
MIT © Daniel Schmidt