Skip to content

Latest commit

 

History

History
59 lines (38 loc) · 1.9 KB

aspect_oriented_programming.md

File metadata and controls

59 lines (38 loc) · 1.9 KB

Aspect Oriented Programming (AOP) guidelines

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.

Prerequisites

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",
	...
},

Use case: Change the return value of an instance method invocation

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"

Use case: Preventing an instance method from being invoked

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"

Use case in portal

You can find an example of use of AOP in FragmentsEditorDragDrop.es.js.