Nick has been so kind to mention the cloning in the design document, so IMHO we are still on topic
Don't think that would solve the problem, since the message (containing an object which need custom cloning) will traverse through the flow through all kind of nodes. And those nodes are not aware of the cloning requirements of the messages passing through them. Moreover a message can contain objects from other nodes also, which might need other special cloning treatment. Nick's router however is nicely positioned between all nodes, so it could do the job. As I said before, he has created a very nice design!!
Will try not to go into too much detail (because this feature is only in an early design status), but that really hurts to be honest . Currently msg cloning in Node-RED simply calls the Lodash cloneDeep function. Suppose we have multiple cloning hook handlers in the future:
- I develop a custom cloning hook handler to clone Opencv matrix objects.
- But another custom cloning hook handler implement custom cloning of another type of objects.
- And so on ...
And all those objects can be available in one single msg! I assume that a cloning hook could e.g. call the Lodash cloneDeepWith function (instead of cloneDeep) which accepts a customizer parameter:
function customizer(value) {
// Ask each custom clone hook handler whether it wants to custom clone this (nested) msg property
if (...) {
return value.cloneNode(true);
}
}
var clonedMsg = lodash.cloneDeepWith(msg, customizer);
But now I'm going to stop brainstorming, otherwise I most certainly will be banned from the Node-RED community