I am trying to use plugins to create a sidebar, based on this gist example.
It seems that the onadd is only called at the beginning.
But I need to do some re-initialization after every deploy (where I can search for the newly deployed nodes).
Unfortunately my Node-RED development time has dropped below freezing point, so I don't have time to start digging into the core.
Can anybody give me a tip about how to handle deployments in a plugin.
You have 3 events that you can add listeners to 'nodes:add', 'nodes:change', 'nodes:remove'.
I use them in combination with an API to detect committed changes vs uncommitted. That's because uibuilder needs to track url names regardless of whether deployed or not.
RED.events.on('nodes:add', function(node) {
if ( node.type === 'uibuilder') {
// Keep a list of uib nodes in the editor
// may be different to the deployed list
editorInstances[node.id] = node.url
// -- IF uibuilderInstances <> editorInstances THEN there are undeployed instances. --
}
})
RED.events.on('nodes:change', function(node) {
if ( node.type === 'uibuilder') {
mylog('nodes:change:', node)
editorInstances[node.id] = node.url
}
})
RED.events.on('nodes:remove', function(node) {
if ( node.type === 'uibuilder') {
mylog('>> nodes:remove >>', node)
delete editorInstances[node.id]
}
})
I think my question was not complete enough. I meant on the server side of the plugin.
My .js file contains this:
RED.plugins.registerPlugin("my-sidebar-plugin", {
onadd: function() {
// The server side code of my plugin
}
})
The onadd is nicely called at the startup, so I can use that to initialize some stuff.
But I was wondering if such a plugin also offered things like ondeploy, onclose, ...
Because I need to execute some code at the server side of my plugin, after a deploy has been executed.
I am aware that my plugin has no data from its own, but I need to collect on the server some information about data of nodes that have been deployed.
Hi Julian,
Nice example in your screenshot!! Very self explaining...
Yes indeed that all works fine for a NODE, but I don't know if that is also possible for a PLUGIN.
I need something similar to your nodeInstance, but for a plugin.
Not sure how I can achieve that.
@BartButenaers There are 4 events of interest (I may not get all the names right): flows:stopping, flows:stopped, flows:starting, and flows:started. I settled to using the flows:started one. You get passed the event type, a diff of nodes (to be removed, to be changed, to be started, something like that...), and the full flow config. The config tells you about all nodes coming from the flow editor, i.e., these are not exactly the running nodes (subflows and that type of fun stuff). But you can then also access the actually running nodes using RED.nodes.getnode. Some code and comments from the node-red flexdash plugin may be helpful.