Skip to content
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

Ensure firing out event #391

Merged
merged 1 commit into from
Aug 5, 2019
Merged

Ensure firing out event #391

merged 1 commit into from
Aug 5, 2019

Conversation

pinussilvestrus
Copy link
Contributor

@pinussilvestrus pinussilvestrus commented Aug 2, 2019

This ensures we definitely fire an element.out event between two hover for different elements. This way we make sure cursor and marker cleanup really got to run, despite the fact some browsers swallow certain mouseout events.

Related to camunda/camunda-modeler#1383

@bpmn-io-tasks bpmn-io-tasks bot added the needs review Review pending label Aug 2, 2019
@pinussilvestrus
Copy link
Contributor Author

This does not affect bpmn-io/bpmn-js#1123 (despite the fact this bug may also be caused by a missing fired event)

@pinussilvestrus pinussilvestrus force-pushed the 1383-out-event-not-fired branch from 78bf231 to e010ee5 Compare August 2, 2019 07:31
Copy link
Member

@nikku nikku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix is substantially different from the HoverFix:

  • it emits a fake element.out event
  • it hooks into low-level DOM events to get the job done

The hover fix on the other hand gets along with:

  • Using already exposed events
  • Faking a dragging.hover event, if non existed

Is there a reason why we're going for a different route for the out fix?

Is there a good reason why we don't combine the two into a single file? I guess using only one of them makes no sense, or does it?

@pinussilvestrus
Copy link
Contributor Author

it emits a fake element.out event

+1 going for executing drag.out instead, should follow to the same result.

it hooks into low-level DOM events to get the job done

This aims to ensure the additional out event is NOT thrown when it was already caught. But yeah true, I'd go for tracking the element.out instead of using the low-level DOM listener.

Is there a good reason why we don't combine the two into a single file?

I think there is not. I wanted to definitely separate the two fixes since they solve different things. Will go for having them in the same module but separate them there instead.

@nikku
Copy link
Member

nikku commented Aug 2, 2019

Why do you expect an additional out event after hover was fired? And if it was thrown, would it hurt?

@pinussilvestrus
Copy link
Contributor Author

Not after the hover, but we have the following happy path in terms of events when we hover from one element to another:

hover Element A -> out Element A -> hover Element B

The bug in camunda/camunda-modeler#1383 is caused by the fact the out event between the two hover's is not fired in some occasions. The fix aims to simply add this missing out if (and only if) it is not fired.

Why so (and does it hurt us if we have multiple out events)? Without the check, we run into side effects

Aug-02-2019 10-33-54

which look like bpmn-io/bpmn-js#1123, but it is happening all the time after adding a connection between two elements (as shown in the screencast). We discussed it with @philippfromme yesterday to add the check to ensure, we will not run into this kind of side effects when triggering unnecessary out operations.

I'll update the PR to the things mentioned above

@nikku
Copy link
Member

nikku commented Aug 2, 2019

Cool. Thanks for the clarification.

@nikku nikku added this to the M30 milestone Aug 2, 2019
@pinussilvestrus
Copy link
Contributor Author

pinussilvestrus commented Aug 2, 2019

One additional finding

it emits a fake element.out event

I tried to go for the drag.out way instead of emitting the element.out event. But at the point we are want to do the out operation for the previousHovered (Element A), the drag context is still set to Element B. This way it removes Element B from the drag context, which leads to side effects (in fact failing test cases).

In fact, waiting for the next drag.hover does not follow to the exact event-order as described from me above. To really achieve this, we would have hook into before a second drag.hover is fired, but after the mouse leaves Element A. This would follow to a similar solution like the current HoverFix. So we have two options

  • NOT using drag.out but emitting element.out for Element A, leave the rest
  • Changing the behavior to hook into before a second drag.hover is fired

@nikku what do you think? I'd personally go for the first one. Benefit: not using expensive operations in additional places ...

@pinussilvestrus pinussilvestrus force-pushed the 1383-out-event-not-fired branch from e010ee5 to 68ecfef Compare August 2, 2019 09:24
@pinussilvestrus
Copy link
Contributor Author

Updated the PR to my preferred version.

@nikku
Copy link
Member

nikku commented Aug 2, 2019

I'll need to look into the issue.

If you have specific requirements regarding the event order, does it make sense to bake these into the test cases? Right now the coverage you provided is very light. I'd assume we verify the actual order and occurrence of events, from hover to out:

expect(emittedEvents).to.eql([
  [ 'drag.hover', ... ],
  [ 'drag.out', ... ]
]);

@pinussilvestrus
Copy link
Contributor Author

Would totally go for additional test coverage, also for the existing HoverFixSpec. Originally planned to take the existing test case to the Hour of Code, since it does not test the overall functionality (despite the fact it's hard to simulate a MouseEvent, which would be needed in this case).

Really like the idea of testing the event order, since this would really ensure the expected behavior. Feel free to add additional thoughts regarding the solutions provided above if you had a deeper look. We can also chat about it next week.

@nikku
Copy link
Member

nikku commented Aug 2, 2019

I'm unsure about whether the things you've mentioned are issues I overlook or whether I came up with a solution that just works.

Could you checkout 87f2b21 and see if it suffers from the same limitations you mentioned?

Please add additional test coverage, regardless of the implementation we are going for. It should not depend on it, anyway. Hint: Do not do dragging.setOptions({ manual: true }) and you can nicely script the drag interaction by simply emitting element.hover / element.out events.

@pinussilvestrus
Copy link
Contributor Author

pinussilvestrus commented Aug 2, 2019

The problem I described does not come out of your implementation because it just solved them 👍 Great approach! It ensures the things I mentioned (cf. out event for correct element) in a good manner I think ❤️

To complete this PR I will

  • transfer your changes to this
  • add additional test coverage

Thanks for your time!

@pinussilvestrus pinussilvestrus changed the title Ensure firing out event WIP Ensure firing out event Aug 2, 2019
@pinussilvestrus pinussilvestrus force-pushed the 1383-out-event-not-fired branch 2 times, most recently from b8ca804 to bd06ae1 Compare August 5, 2019 05:45
@pinussilvestrus pinussilvestrus changed the title WIP Ensure firing out event Ensure firing out event Aug 5, 2019
@pinussilvestrus
Copy link
Contributor Author

Ready to review now!

After finishing, I was not able to reproduce bpmn-io/bpmn-js#1123 again. Could be just luck or we really tackled this problem here as well. We will have to double-check it then.

Also tried to improve the existing test in HoverSpec but it revealed as being very hard to mock proper mouse events for this case. Let's postpone this for a future Hour of Code.

@pinussilvestrus pinussilvestrus requested a review from nikku August 5, 2019 06:01
@pinussilvestrus pinussilvestrus force-pushed the 1383-out-event-not-fired branch 2 times, most recently from 3852203 to 6593346 Compare August 5, 2019 08:02
@nikku nikku force-pushed the 1383-out-event-not-fired branch from 6593346 to b94a412 Compare August 5, 2019 08:10
@merge-me merge-me bot merged commit c17b75c into master Aug 5, 2019
@bpmn-io-tasks bpmn-io-tasks bot removed the needs review Review pending label Aug 5, 2019
@delete-merged-branch delete-merged-branch bot deleted the 1383-out-event-not-fired branch August 5, 2019 08:13
@nikku nikku modified the milestones: M30, M29.2 Aug 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants