Plugin structure & registration
Plugin structure & registration
Plugin structure
A plugin is an object with a stable id and a setup function:
Treat id as the plugin’s identity within a single uploader context. It must be unique for that context.
The setup function receives a single object with the following properties:
setup can be synchronous or async. It can also return a disposer function that runs when the plugin is unregistered.
Registering plugins
Pass plugins to the <uc-config> element via its plugins property:
Or in a framework (React example):
The uploader’s built-in plugins (camera, image editor, external sources, and others) are managed separately and merged in automatically based on your config, so setting plugins only affects your custom plugins.
Plugins are initialized in array order. Replacing cfg.plugins causes the uploader to resync the list: removed plugins are disposed, new plugins are set up, and duplicates by id are skipped.
To add or remove a plugin at runtime, assign a new array to plugins. Mutating the existing array in place — for example with push() or splice() — is not supported and produces non-deterministic results: the mutation may occasionally be picked up due to a timing race with async lazy-plugin loading, but this is not guaranteed and will silently break under different conditions. Always replace the array:
Cleanup and disposal
If setup returns a disposer function, it runs when the plugin is removed from the plugins array or when the uploader is destroyed.
Subscriptions created with pluginApi.config.subscribe and pluginApi.activity.subscribeToParams inside setup are cleaned up automatically when the plugin is unregistered. If you create subscriptions inside an activity’s render function, unsubscribe them in the cleanup function returned from render so they do not outlive that activity mount.