From 6f25337b999c66f6a1ea60b9f0da8e6e28997136 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 31 Jul 2020 14:31:33 +0100 Subject: [PATCH] Add docs for RED.hooks --- .../@node-red/runtime/lib/hooks.js | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/packages/node_modules/@node-red/runtime/lib/hooks.js b/packages/node_modules/@node-red/runtime/lib/hooks.js index b8333302f..10303ed55 100644 --- a/packages/node_modules/@node-red/runtime/lib/hooks.js +++ b/packages/node_modules/@node-red/runtime/lib/hooks.js @@ -11,6 +11,18 @@ let labelledHooks = { } /** * Runtime hooks engine + * + * The following hooks can be used: + * + * Message sending + * - `onSend` - passed an array of `SendEvent` objects. The messages inside these objects are exactly what the node has passed to `node.send` - meaning there could be duplicate references to the same message object. + * - `preRoute` - passed a `SendEvent` + * - `preDeliver` - passed a `SendEvent`. The local router has identified the node it is going to send to. At this point, the message has been cloned if needed. + * - `postDeliver` - passed a `SendEvent`. The message has been dispatched to be delivered asynchronously (unless the sync delivery flag is set, in which case it would be continue as synchronous delivery) + * - `onReceive` - passed a `ReceiveEvent` when a node is about to receive a message + * - `postReceive` - passed a `ReceiveEvent` when the message has been given to the node's `input` handler(s) + * - `onComplete` - passed a `CompleteEvent` when the node has completed with a message or logged an error + * * @mixin @node-red/runtime_hooks */ @@ -132,25 +144,6 @@ function trigger(hookId, payload, done) { } } -// add("preSend", function(sendEvents) { -// console.log("preSend",JSON.stringify(sendEvents)); -// }) -// add("preRoute", function(sendEvent) { -// console.log("preRoute",JSON.stringify(sendEvent.msg)); -// }) -// add("onSend", function(sendEvent) { -// console.log("onSend",JSON.stringify(sendEvent.msg)); -// }) -// add("postSend", function(sendEvent) { -// console.log("postSend",JSON.stringify(sendEvent.msg)); -// }) -// add("onReceive", function(recEvent) { -// console.log("onReceive",recEvent.destination.id,JSON.stringify(recEvent.msg)) -// }) -// add("postReceive", function(recEvent) { -// console.log("postReceive",recEvent.destination.id,JSON.stringify(recEvent.msg)) -// }) - function clear() { hooks = {} labelledHooks = {}