-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
refactor(eventStack): make eventStack immutable #2837
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2837 +/- ##
=======================================
Coverage 99.66% 99.66%
=======================================
Files 161 161
Lines 2722 2722
=======================================
Hits 2713 2713
Misses 9 9 Continue to review full report at Codecov.
|
return | ||
} | ||
|
||
const recentHandler = [...this.handlers].pop() |
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.
EDIT - Oh, this is a Set, not an array... you can ignore my original
Rather than cloning the entire array to get the last handler, you can directly access the last item:
const recentHandler = this.handlers.slice(-1)[0]
// or
const recentHandler = this.handlers[this.handlers.length - 1]
Note, the spread approach, the slice approach, and the length approach all avoid mutating the this.handlers
array, however, the recentHandler
is not a unique instance. It is the same instance as was originally provided to the array of handlers. I'm not sure if this matters to you or not.
import normalizeHandlers from './normalizeHandlers' | ||
import normalizeTarget from './normalizeTarget' | ||
|
||
export default class EventStack { |
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.
It would be helpful to have a description above the EventSet, EventStack, and EventPool. It is not immediately clear how the 3 operate together.
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.
@levithomason I've added a README file with description
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.
See comments. This looks good, just a request for a little more documentation on the classes.
…React into refactor/event-stack Signed-off-by: Oleksandr Fediashov <[email protected]>
Signed-off-by: Oleksandr Fediashov <[email protected]>
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.
I've updated the EventStack README a bit. If it looks good, this can be merged. Thanks for the excellent write up!
Merging for progress. Any doc tweaks can happen in another PR 💪 |
Released in |
Why?
Sometime ago I tried to attack #1473, I've fully reworked the
Sidebar
component and docs. But then I found a strange problem when tested the component: event handlers simply called before they should be called. I've found the problem, it was in the mutable array ofhandlers
in theEventTarget
.This PR performs the deep refactoring and adds more test coverage for internals of the
eventStack
.The easiest way to show problem: just clone
feat/sidebar-closable-property
branch and try to run theSidebar
examples without & with these changes.