-
Notifications
You must be signed in to change notification settings - Fork 98
feat: Workflow tools #570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Workflow tools #570
Conversation
|
@madeindjs You always share some good advice :) Happy to provide more context for these features if necessary. |
| setTimeout(() => { | ||
| // Debouncing | ||
| if (component.x !== newX) return; | ||
| if (component.y !== newY) return; | ||
| changeCoordinates(componentId, newX, newY); | ||
| }, 200); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's a debouncer you want, you might need to cancel the previous setTimeout using a method like
function useDebouncer<Args extends Array<unknown>, Return>(
callback: (...args: Args) => void,
ms: number,
): (...args: Args) => void {
let id: ReturnType<typeof setTimeout>;
return (...args: Args) => {
if (id) clearTimeout(id);
id = setTimeout(() => callback(...args), ms);
};
}
const changeCoordinatesDebounced = useDeboucer(changeCoordinates, 200);and then
| setTimeout(() => { | |
| // Debouncing | |
| if (component.x !== newX) return; | |
| if (component.y !== newY) return; | |
| changeCoordinates(componentId, newX, newY); | |
| }, 200); | |
| changeCoordinatesDebounced(componentId, newX, newY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that was the other alternative but I wanted to avoid having a single timer id for all components. So I'd have needed Record<Component["id"], ReturnType<typeof setTimeout>> and I wanted to avoid.
However, in the example you declare id inside the function. If it works that'd be great, but how would that behave? Wouldn't future calls get a completely new id since it's scoped to the function?
| postChildren.forEach((c) => { | ||
| if (!c.outs || c.outs.length == 0) return; | ||
| c.outs = c.outs.filter((out) => out.toNodeId !== removedId); | ||
| await nextTick(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this nextTick necessary ? It's a bit dangerous to use it inside a watch, no ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I need to have everything reflected on the DOM before I call refreshArrows, since this function calls getBoundingClientRect() to get precise coordinates.
Co-authored-by: Alexandre Rousseau <alexandre@rsseau.fr>
Co-authored-by: Alexandre Rousseau <alexandre@rsseau.fr>
Co-authored-by: Alexandre Rousseau <alexandre@rsseau.fr>
Co-authored-by: Alexandre Rousseau <alexandre@rsseau.fr>
No description provided.