AOP provides tools to improve control of what is executed before and after another method is invoked. You can find this component in the frontend-js-web
module.
See more about Aspect Oriented Programming in this article.
First of all the frontend-js-web
dependency should be added to the package.json
of the module in which we'll use AOP. Be sure that the version matches the one in frontend-js-web/bnd.bnd
.
"dependencies": {
...
"frontend-js-web": "4.0.0",
...
},
import {AOP} from `frontend-js-web`;
const foo = new Foo();
foo.bar(); // "bar"
const _interceptedFoo = AOP.after(target => {
return AOP.alterReturn("modified bar");
}, foo, 'bar');
foo.bar(); // "modified bar"
handle.detach(); // We can detach the interception
foo.bar(); // "bar"
import {AOP} from `frontend-js-web`;
const foo = new Foo();
foo.bar(); // "bar"
const _interceptedFoo = AOP.before(target => {
return AOP.prevent();
}, foo, 'bar');
foo.bar(); // undefined
handle.detach(); // We can detach the interception
foo.bar(); // "bar"
You can find an example of use of AOP in FragmentsEditorDragDrop.es.js.