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

[OverflowList] add onOverflow callback prop #2975

Merged
merged 11 commits into from
Oct 4, 2018
Merged

Conversation

giladgray
Copy link
Contributor

@giladgray giladgray commented Sep 26, 2018

Changes proposed in this pull request:

  • add OverflowList onOverflow callback prop which receives the overflowed items.
  • invoked at most once per resize and only if the overflowed items actually changed.
    • this was tricky to support but i got it working nicely!

Reviewers should focus on:

  • reliability of this code change.

Screenshot

overflow-list-onoverflow

import { IResizeEntry, ResizeSensor } from "../resize-sensor/resizeSensor";

/** @internal - do not expose this type */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

thoughts on doing this to reduce the exported surface area? it excludes it from the .d.ts files and required marking the state field similarly (line 84).

Copy link
Contributor

Choose a reason for hiding this comment

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

🆒

@blueprint-bot
Copy link

more onOverflow tests & helper

Previews: documentation | landing | table

this.repartition(false);
if (this.state.direction === OverflowDirection.NONE && this.state.direction !== prevState.direction) {
if (
Copy link
Member

Choose a reason for hiding this comment

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

this could be just one if

*/
direction: OverflowDirection;
/** Remember the last completed overflow to dedupe `onOverflow` calls during smooth resizing. */
lastOverflow?: T[];
Copy link
Member

Choose a reason for hiding this comment

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

if you make this non-optional you have one fewer check to make below. You don't actually treat the undefined case in a special way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

undefined is different from empty list. the distinction is actually useful.

@blueprint-bot
Copy link

more docs, combine if

Previews: documentation | landing | table

2 similar comments
@blueprint-bot
Copy link

more docs, combine if

Previews: documentation | landing | table

@blueprint-bot
Copy link

more docs, combine if

Previews: documentation | landing | table

@blueprint-bot
Copy link

reset lastOverflow with new props

Previews: documentation | landing | table

Copy link
Contributor

@cmslewis cmslewis left a comment

Choose a reason for hiding this comment

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

// shrink operation does not require checking last items
(prevState.direction === OverflowDirection.SHRINK ||
// if current overflow is different from last completed state
this.state.lastOverflow == null ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we do === undefined, or is == null just idiomatic for the codebase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

idiomatic

(prevState.direction === OverflowDirection.SHRINK ||
// if current overflow is different from last completed state
this.state.lastOverflow == null ||
this.state.lastOverflow.some((x, i) => x !== this.state.overflow[i]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we just check lastOverflow.length !== overflow.length to save a little time? Is it possible for a change in overflow to replace items without changing the number of items displayed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes it's completely possible for that to happen, though that should be handled by the check in componentWillReceiveProps. so maybe this check can be made simpler. i'll play with it some more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

worked flawlessly!

import { IResizeEntry, ResizeSensor } from "../resize-sensor/resizeSensor";

/** @internal - do not expose this type */
Copy link
Contributor

Choose a reason for hiding this comment

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

🆒

@blueprint-bot
Copy link

simplify lastOverflow check - just length

Previews: documentation | landing | table

// if a resize operation has just completed (transition to NONE)
direction === OverflowDirection.NONE &&
direction !== prevState.direction &&
(lastOverflowCount == null || overflow.length !== lastOverflowCount)
Copy link
Member

Choose a reason for hiding this comment

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

this is never set to null or undefined, so the first part will never be true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh yeah i removed the nullability!

@@ -85,6 +107,8 @@ export class OverflowList<T> extends React.PureComponent<IOverflowListProps<T>,
}

public state: IOverflowListState<T> = {
direction: OverflowDirection.NONE,
lastOverflowCount: -1,
Copy link
Member

Choose a reason for hiding this comment

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

Why -1? The overflow initially has 0 elements.

@@ -85,6 +107,8 @@ export class OverflowList<T> extends React.PureComponent<IOverflowListProps<T>,
}

public state: IOverflowListState<T> = {
direction: OverflowDirection.NONE,
Copy link
Member

Choose a reason for hiding this comment

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

We initially call repartition in shrinking mode, so maybe this should be SHRINK (if you want onOverflow to be called initially, even when the overflow is empty. If you don't, just keep NONE)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i changed to SHRINK but it was not called initially in tests, so just sticking with this.

@blueprint-bot
Copy link

lastOverflowCount defaults to 0

Previews: documentation | landing | table

Copy link
Member

@invliD invliD left a comment

Choose a reason for hiding this comment

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

❤️

this.setState({
this.setState(state => ({
direction: OverflowDirection.GROW,
// store last overflow if this is the beginning of a resize (for check in `update()`).
Copy link
Member

Choose a reason for hiding this comment

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

can you call this componentDidUpdate or remove the backticks and parens so it's clearer what you mean?

@blueprint-bot
Copy link

fix name in comment

Previews: documentation | landing | table

@blueprint-bot
Copy link

fix name in comment

Previews: documentation | landing | table

@giladgray giladgray merged commit 8f86ea9 into develop Oct 4, 2018
@giladgray giladgray deleted the gg/overflow-list-event branch October 4, 2018 19:38
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.

4 participants