hufftheweevil / node-red-contrib-persistent-fsm

A Node Red node that wraps around Javascript State Machine
Other
4 stars 7 forks source link

Multiple initial messages following fsm node edit, due to incorrect removeListener call #9

Closed colinl closed 1 year ago

colinl commented 2 years ago

To see the problem add a state machine node to the flow and connect it to a debug node. Open the state machine node, add a state and a transition specification. Leave the Initial Delay at 0. Deploy and note that the "start" task message appears in the debug pane. Open the state machine node and add another task. Perform a Modified Nodes deploy. Note that two "start" messages are seen. Move the debug node a little and Deploy again, again two messages are produced. If the state node is modified again then the number increases. Restart node-red and then only one message is seen.

I believe the cause to be incorrect removal of the flows:started event. If the line adding the event RED.events.on('flows:started', function () { is changed to let f; RED.events.on('flows:started', f=function () { and the line removing it RED.events.removeListener('flows:started', node.startup) is changed to RED.events.removeListener('flows:started', f) then that appears to fix it. However I am no expert in this area so that may not be the correct way to fix it.

I am using fsm node 1.2.0, NR 3.0.2, nodejs 16.17.0

hufftheweevil commented 1 year ago

Fixed in v1.2.1 Thank you!