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.
https://github.com/NodeBB/NodeBB/blob/master/src/plugins.js#L38
-
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().
https://github.com/pitaj/nodebb-plugin-calendar/blob/master/library.js#L831
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)
https://github.com/NodeBB/NodeBB/blob/master/src/webserver.js#L56
-
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