Share information between plugins
-
Hi! How can i share information between plugins? I've made BBCode plugin and now i want to create extension plugin to support new feature with new bb codem so i need to somehow inject this information into the first plugin. Do you have any mechanics for this?
-
The plugins library file is loaded into Plugins.libraries, so anything that is exported in the library can be accessed by other plugins, after they are both loaded, using the pluginid.
File not found · NodeBB/NodeBB
Node.js based forum software built for the modern web - File not found · NodeBB/NodeBB
GitHub (github.com)
-
But in your case, you might want to fire a an event on your bbcode plugin, and have the addon listen for it. Like the composer does with formatting buttons.
-
Does order of plugins matter in these cases?
-
@Nicolas Yes, neither of those methods would work until after both the plugins are loaded.
Here's an example where @pitaj requires the library directly. That's the only way I know of to actually use the other plugin in your init().
nodebb-plugin-calendar/library.js at master · pitaj/nodebb-plugin-calendar
Fully-featured calendar plugin for NodeBB. Contribute to pitaj/nodebb-plugin-calendar development by creating an account on GitHub.
GitHub (github.com)
But, you would still have the problem that the plugin has not loaded yet, and some features may not work. It would be nice if there was a hook for when a plugin is loaded, but I don't see one.
-
You could look for when nodebb is ready (this implies plugins are all loaded)
NodeBB/src/webserver.js at master · NodeBB/NodeBB
Node.js based forum software built for the modern web - NodeBB/src/webserver.js at master · NodeBB/NodeBB
GitHub (github.com)
-
I've used hook method in my bbcode plugin (watch Extension block here - http://forum.apxeolog.com/topic/8/nodebb-bbcode-plugin)
It is greate since:- If there is no 'parent' plugin there will be no errors (noone call the hook)
- Plugin priority dosn't matter because hooks should be called after all plugins are loaded