Debounce
The Debounce node is used to control the rate of flow in a spell by introducing a delay between the input and output flows. It is particularly useful when you want to limit the frequency of a certain action or event, such as making API requests or updating a UI element.Inputs
flow: The input flow that triggers the debounce.waitDuration: The amount of time (in seconds) to wait before allowing the flow to continue. Default value is 0.cancel: An optional flow input that, when triggered, cancels the current debounce and resets the timer.
Outputs
flow: The output flow that is triggered after the specifiedwaitDurationhas elapsed since the last inputflowtrigger.
Configuration
This node has no additional configuration options.Usage
- Connect the
flowinput to the event or action you want to debounce. - Set the
waitDurationinput to the desired delay time in seconds. - Optionally, connect the
cancelinput to a flow that should cancel the current debounce and reset the timer. - Connect the
flowoutput to the nodes that should be triggered after the debounce delay.
Example
Suppose you have a spell that makes an API request every time a user types in a search box. To avoid making too many requests while the user is still typing, you can use the Debounce node to introduce a short delay:Best Practices
- Choose an appropriate
waitDurationbased on the specific use case. A longer duration will reduce the frequency of the debounced action but may feel less responsive to the user. - Use the
cancelinput when you need a way to immediately cancel a pending debounce and reset the timer, such as when the user clears the search box.
Common Issues
- If the
waitDurationis set too low, the debounce may not have a noticeable effect on the flow rate. - Be mindful of where you place the Debounce node in your spell. Placing it too early or too late in the flow can lead to unexpected behavior.
