Starting with v1.1, the function node now has the setup and close tab. This initially got me very excited.
However, when thinking about possible use cases with the current functionality in more detail, I mostly can see the purpose in initializing context variables.
I came up with a few other ideas which would require quite a different philosophy of the node, so I would like to hear your opinions on that and maybe also what other use cases are you can think of with the functionality as it is today.
As far as I can see, the setup handler does not support all features of the main function body.
node.status cannot be used (workaround working today
But more importantly, I thought about using the setup handler to access an npm module, call its constructor and maybe establish some callbacks from the module, which then would send out a message if they are called. An example would be an npm module that connects to some service and has a callback when a message from the service is received. In order to do so, one would need access to the
done function in the setup handler.
It seems that such a functionality is against the philosophy of the function node in its current form. For example, the node would "wait" (in the async sense) until the code in setup handler has finished and then only goes on with processing messages.
It is also not clear to me if storing an instance of the npm module in the context is a good idea in this case (to share it between the setup and the main function body)
The code in the close handler does, as far as I can see, not allow async function calls, which would also be required if the above mentioned functionality would be considered.
I personally would not be sure if I would use it much, since I could also just create a custom node, but maybe for one time things where you also don't need to create a ui for configuration, this might be an interesting idea, I think.