Skip to content
ly685 edited this page Aug 19, 2014 · 9 revisions

Design notes for #322

Currently, the palette of nodes is loaded when the runtime starts and does not change.

The runtime needs to allow nodes to be added/removed dynamically.

Some points that need to be considered:

  • nodes can be added by dropping files into the node path, or by npm. Both of these mechanisms should be supported by this feature
    • adding by file will expect the file to have already been copied into node path
    • adding by npm will trigger an npm install of the module
    • future support for importing a zip or files themselves?
  • removing a node cannot 'unload' the module - care must be taken if the node creates any 'static' resources
  • removing a node in the editor must allow it to remove any artefacts added to the page (eg, debug node's tab)
  • a node file or module can contain multiple nodes. Making a request to remove a single node type may trigger the removal of multiple node types.
  • what to do if the node is being used in the current flow? Safest option is to reject the removal.
  • removing a node, without also removing the files, will mean it returns to the palette on the next restart. That would be unexpected.

Adding a node type

To add a new node to the palette:

  1. a request is POSTed to {admin root}/nodes to trigger the add. The post body is a JSON structure that identifies where the node information comes from, either a local file (file) or an npm module (module).

     {
         file: "path to local node .js file or package.json",
         module: "npm module name"
     }
    
  2. An event is fired over the comms link telling any connected editors that nodes have been added. This triggers a HTTP Get back to {admin root}/nodes/{node-set-id} to load the node definition/help/edit template.

Remove node type

To remove a node from the palette:

  1. a DELETE http request is sent to {admin root}/nodes/{node-set-id} to trigger the removal.
  2. If the any of the corresponding nodes are in use, the request is rejected
  3. The runtime registry removes the corresponding nodes.
  4. An event is fired over the comms link telling any connected editors that the nodes have been removed.

Question

@knolleary : Ref the point about multiple nodes:

  • a node file or module can contain multiple nodes. Making a request to remove a single node type may trigger the removal of multiple node types. Is it possible to have two options? One to remove a specific node and a second to remove the collection? I am thinking of a use case where a Node module contains (for instance) 5 nodes for a specific use case (e.g, home automation), and I want to/will regularly use 3 of those nodes in the bundle but not interested in 2 of them. Can I just remove the 2 nodes to have a cleaner palette and runtime? PS: This section can be removed when dealt with

Clone this wiki locally