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

refactor(eventStack): make eventStack immutable #2837

Merged
merged 5 commits into from
Jun 1, 2018

Conversation

layershifter
Copy link
Member

@layershifter layershifter commented May 25, 2018

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 of handlers in the EventTarget.

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 the Sidebar examples without & with these changes.

@codecov-io
Copy link

codecov-io commented May 25, 2018

Codecov Report

Merging #2837 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3a30105...0ba029a. Read the comment docs.

return
}

const recentHandler = [...this.handlers].pop()
Copy link
Member

@levithomason levithomason May 31, 2018

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 {
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

@levithomason levithomason left a 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.

Oleksandr Fediashov added 2 commits June 1, 2018 13:55
Signed-off-by: Oleksandr Fediashov <[email protected]>
Copy link
Member

@levithomason levithomason left a 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!

@levithomason
Copy link
Member

Merging for progress. Any doc tweaks can happen in another PR 💪

@levithomason levithomason merged commit fd269d6 into master Jun 1, 2018
@layershifter layershifter deleted the refactor/event-stack branch June 1, 2018 19:01
@levithomason
Copy link
Member

Released in [email protected].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants