feat(plugins): add support for plugin decorators #2971
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
This PR adds support for registering plugin decorators. This is useful for our old POJO plugins (and we have many of those), as very often in our code we do conditional checks if certain optional plugin properties are set, and if so, execute those functions. This adds a lot of overhead in various views where same plugin types are being used.
Using decorators we can now register decorators (classes), which decorate (wrap) the original plugin, and that way we can implement default behavior on those optional plugin functions.
Why not just switch the original plugins with classes?
Because there are many plugins in the user land, which would break the app if we just assumed that everybody is now using classes. This way we can add a decorator and achieve the same result without breaking anything, and remove the redundant conditionals from our main logic.
@brunozoric @adrians5j please have a look at the tests and post your thoughts.
How Has This Been Tested?
Jest tests.