You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cool example. Notice that it has a "subscriptions leak" issue - transformDraggedElement runs multiple times (e.g when the dragged element enters the dndzone). Maybe check whether a subscription already exists before subscribing or do it differently, e.g when drag starts (it will have the trigger DRAG_STARTED) you could find the dragged element in the DOM with getElementById and run your code.
saved, changes here. was also leaking, since the Element will always exist (but not the node) so subscribes would run after dragging was done
letisDragging=false;functiontransformDraggedElement(draggedEl,data,index){letunsubscribe;//make sure we only subscribe once, by tracking if we're already draggingif(!isDragging){isDragging=true;//subscribe to store in object, and set value indentical to what the markup would be `(x*100).toFixed(0)`unsubscribe=data.name.subscribe((name)=>{unsubscribeIfNeeded();console.log("running",isDragging)draggedEl.querySelector("div").innerText=(name*100).toFixed(0);})}functionunsubscribeIfNeeded(){if(!document.contains(draggedEl)&&unsubscribe){console.log("unsubscribe")unsubscribe();isDragging=false;}}}```
Was having trouble figuring this out, and thought this might be a good example to share:
https://svelte.dev/repl/20fa1a8496c8467f9a99d125ce41d9c9?version=3.59.2
The text was updated successfully, but these errors were encountered: