The Modern.js plugin system is constantly evolving. To provide a clearer API and more powerful features, we've optimized the definition and usage of Runtime plugins. While the old plugin syntax is still partially compatible, we strongly recommend migrating according to this guide to take full advantage of the new plugin system.
Plugin
type with RuntimePluginFuture
.return hooks
pattern to direct api.xxx
calls.This is the first and most crucial step. It ensures that your plugin interacts correctly with the new plugin system.
Explanation: The RuntimePluginFuture
type is the standard definition for new plugins. It provides better type inference and a clearer API structure.
The new plugin system recommends using the api
object to directly call Hooks. This approach is more intuitive and easier to maintain.
Explanation: The api
object provides all available Hooks and utility methods.
To maintain API consistency and clarity, we've adjusted the names of some APIs. Additionally, the hoc
and init
Hooks have been removed. Please use the new Hooks as replacements. The table below lists all changed APIs and their old and new counterparts:
Old API | New API | Description |
---|---|---|
beforeRender |
onBeforeRender |
Executed before application rendering. |
hoc |
wrapRoot |
Important Change: Used to wrap the root component, achieving the functionality of a Higher-Order Component (HOC). Make sure to pass props to the original component. |
init |
onBeforeRender |
Important Change: Execute initialization logic before application rendering. This replaces the previous init hook. Use onBeforeRender to perform any setup or initialization tasks that were previously done in init . This provides a single, consistent point for pre-rendering logic. |
Explanation:
onBeforeRender
replaces both the original beforeRender
and init
, used for pre-rendering logic and initialization, respectively.wrapRoot
replaces hoc
and is used to implement higher-order component functionality. It's crucial to pass props correctly when using wrapRoot
.wrapRoot
Usage Example:
Q: Will my plugin still work correctly after migration?
A: As long as you've correctly completed all the steps in this guide, your plugin should function properly. If you encounter any issues, please refer to the official Modern.js documentation or seek community support.
Q: Do I have to migrate my plugin immediately?
A: While the old plugin syntax remains partially compatible, we strongly recommend migrating as soon as possible. The new plugin system offers improved performance and richer functionality, making migration worthwhile in the long run.
Q: Where can I find more information about the new plugin system?
A: Please consult the official Modern.js documentation, especially the section on the plugin system. You can also refer to examples of other migrated plugins to understand best practices.
With this detailed migration guide, we hope to help you smoothly transition your Runtime plugins to the new Modern.js plugin system. If you encounter any problems during the migration process, please don't hesitate to ask for assistance.