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

fix: trigger not handling all event handlers #53

Merged
merged 2 commits into from Mar 11, 2021

Conversation

WoodNeck
Copy link
Member

Issue

#52

Details

This fixes #52

@WoodNeck WoodNeck added the bug label Mar 10, 2021
@WoodNeck WoodNeck requested review from mixed and daybrush March 10, 2021 08:03
@WoodNeck WoodNeck self-assigned this Mar 10, 2021
@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 93.985% when pulling 1f0011e on WoodNeck:fix-trigger-not-finished#52 into f39c2fd on naver:master.

Copy link
Member

@daybrush daybrush left a comment

Choose a reason for hiding this comment

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

LGTM.

This method is executed even if the next handler is deleted.

However, if it check individually, it will cost a lot of checking.

@WoodNeck
Copy link
Member Author

LGTM.

This method is executed even if the next handler is deleted.

However, if it check individually, it will cost a lot of checking.

This fix is for when the previous handler is removed.
image
The simplest representative code might look like the above screenshot,

@daybrush
Copy link
Member

@WoodNeck

The example seems a little different.

const arr = [0, 1, 2];
const handlers = [...arr];

handlers.forEach(handler => {
   arr.splice(0, 1);
   console.log(handler);
});

@WoodNeck
Copy link
Member Author

@daybrush
Of course that's different as I'm representing the previous code...

@daybrush
Copy link
Member

@WoodNeck

You are right. The method you said is a good one because it doesn't get any errors.

What I'm talking about is a future problem. Events will continue to be triggered even after the event is released or destroyed.

@WoodNeck
Copy link
Member Author

I'm fixing the issue of the handler removing itself here especially by calling once, and what you're saying is handlers removing each other.
I think that shouldn't happen, as that's highly dependent on the order of events attached.
And as we don't guarantee event order in any of our code, that's totally the user's fault doing that.
The user simply can bypass it by merging to handlers attached to the same event and conditionally handle them inside.
So IMO, event handlers shouldn't remove each other and it's okay to trigger events even if it's removed before calling them.

Copy link
Member

@mixed mixed left a comment

Choose a reason for hiding this comment

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

🥇

@WoodNeck WoodNeck merged commit 1cb1bb5 into naver:master Mar 11, 2021
@WoodNeck WoodNeck deleted the fix-trigger-not-finished#52 branch March 11, 2021 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

trigger is not handling all handlers when some handlers are removed while calling it
4 participants