-
-
Notifications
You must be signed in to change notification settings - Fork 166
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
Add node Variable moved. And fire the nodeReleased Event #403
base: main
Are you sure you want to change the base?
Conversation
I want to add this because, i want to update the position in DB of the node after the movement. For supporting the old functionality, nodeReleased without movement (that was the the functionality before my change) i added the moved value. With that can be checked if it moved an in addition to that, in what direction and how far it get moved. |
I'll take a look at this over the weekend. At the moment, I think my preference would be to add a separate on:nodeMoved event, but I'll see what it's like with this approach and get back to you. |
I understand you but less events are maybe better, and the original motivation to change it, was that released was not fired if the node was moved. |
I understand and appreciate what you're trying to achieve @Trackhe, but don't think this is the right pattern. I believe that there is an intuitive way that developers expect this to behave based on analogous native browser events and the expectations of end users. I think the naming in the current library has been poorly chosen (by me) and I believe additional events are needed, but I want to stick as closely as possible to familiar, intuitive patterns and believe the decision to have this particular event fire only when the Node has not moved is the correct one. To explain, consider the following: <div class="wrapper">
<div
class="element"
draggable="true"
on:dragstart={() => console.log('start')}
on:drag={() => console.log('drag')}
on:dragend={() => console.log('end')}
on:mouseup={() => console.log('mouse up')}
on:mousedown={() => console.log('mouse down')}
/>
</div>
For the sake of argument, consider something as simple as a draggable button. Obviously, there is some functionality that should be triggered when the button is clicked. Let's say the button changes from red to blue. If the button can also be moved around the page via some kind of drag interaction, I believe the vast majority of users would expect the color of the button to remain unchanged after repositioning it. Yes, they clicked the button and then released, but their intention was not to "click" the button, it was to move it. My point is that 99 times out of 100, any event you want to trigger If we were to implement the method proposed in this PR, the vast majority of functions triggered by this event would require a conditional check as the first line of the function to ensure the Node has not moved. Instead, we should add an additional event, analogous to I'll also argue that more events are the preferred, standard API. You don't just have That said, thank you very much for the work put into this PR. I'd be happy to continue to discuss the changes around this space and review any PRs in the future. |
I'd definitely be keen for an Also, this event would be very handy for implementing undo/redo as described in #426. |
If I have time, I will make the code changes and split it into two events. However, even with these changes, the "nodeReleased" event should still fire every time the node is released, regardless of its positioning, as that could be misleading. In my opinion is the renaming of the original event necessary. I would prefer here to get rid of the "nodeClicked" and "nodeReleased" and name it, as you already mentioned "on:click, on:mousedown and on:mouseup" but i m open for other and at least this is your project. like what are you saying <div class="wrapper">
<div
class="element"
draggable="true"
on:dragstart={() => console.log('start')}
on:drag={() => console.log('drag')}
on:dragend={() => console.log('end')}
on:mouseup={() => console.log('mouse up')}
on:mousedown={() => console.log('mouse down')}
/>
</div> if i found time i implement it like this. |
Add node Variable moved. And fire the nodeReleased Event on every release, not only if the Node was not moved. If you want to check if it was released without movement, check it with:
I created an example too. routes/events, open the javascript console and try it out.