I've been hacking away at RED.library, trying to understand how it works. I'm actually getting somewhere and managed to save and read information from the library in my test node.
However, I have a question. Is there a way to use the library function and NOT use an editor?
RED.library.create({
url:"templates", // where to get the data from
type:"template", // the type of object the library is for
editor:that.editor, // the field name the main text body goes to
fields:['name'],
ext: "txt"
});
I've tried to not including the editor parameter, which fails, and tried to just create an editor object and not use it, which works but looks kinda ugly:
RED.library.create({
url:"templates", // where to get the data from
type:"template", // the type of object the library is for
editor:RED.editor.createEditor()
});
Not sure there is a way to skip it. The only uses of the library API for saving individual nodes has been for nodes that have an editor - such as the Function and Template nodes. So it is probably a built-in assumption that there is a editor to save/restore from.
I'm sure it's something that could be improved if there was a specific requirement.
I want to use it to save a definition of a Thing in node-red-contrib-hal2, to use as a template for creating other similar Things so you don't have to start from scratch each time. I'll try it, see how far I get!
Okay, this actually worked pretty well, but I did run into a few problems.
RED.editor obviously, but I got around that by creating an editor object and just not use it.
The node where I want to use RED.library is actually a config node, and RED.library didn't like that much. I ended up creating a hidden input with id='node-input-name' and kept it up to date with an on change function in 'oneditprepare'. Kinda ugly, but works.