feat: slot component for dynamic plugins #183
Closed
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.
Description
, we've created a reusable component that will dynamically import a module wherever it is called. The main idea is to be able to change the plugins with this mechanism, which means that instead of modifying the micro-frontend beforehand, we could change the plugin in isolation.
How does it work?
Any component can be wrapped with the pluggable component. For instance:
The prop
as
indicates where is the plugin allocated. In this case, the component will be pointing to this route:node_modules/@openedx-plugins/communications-app-card
.If the plugin was installed as a dependency, it will render the component that you have pointing to that one.
If the plugin isn't installed, it will return its children. In this case, it's this:
Why are we doing this?
This means that the plugin doesn't have to be installed if I'm making a feature. It's something that we can improve in the future. That way, another developer can replace that component and make more changes. This approach allows us to wrap as many components as we can, making most of the features pluggable and adaptable to various use cases. The component can be rendered without children as well, which means it won't return anything if the plugin is not installed.
How to test it
Check it out this branch and follow these steps:
Then you can run the mfe with
npm start
If you want to create another plugin you can do it in the folder plugins/communications-app/ with the structure of the other
plugins