-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Optimize the first rendering of the report main view and the report actions view #498
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
Changes from all commits
845460d
f447382
fbab50d
8fa9a37
4457014
8ed7f31
ceb3c90
9c5cea5
8160cec
5891973
901585a
f6672dd
4f1a229
c0a3ded
3f77ea9
6293c58
41fa8a1
9d9a2f8
e0c2063
fe7ddf9
a7388c3
8d6f0cf
35824f1
971442e
4cf1e06
d297927
b189b8c
1ac8155
ae0406a
f344c2b
34a0fa6
7fc19f5
c4e22d4
9806698
0559a57
2f718e3
1230443
5faccd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /** | ||
| * This HOC is used to incrementally display a collection of data in batches. | ||
| * Example: in MainView.js only the visible reports should be rendered in the first batch, | ||
| * then all other reports are rendered in the second batch | ||
| */ | ||
| import React, {Component} from 'react'; | ||
| import _ from 'underscore'; | ||
|
|
||
| /** | ||
| * Returns the display name of a component | ||
| * | ||
| * @param {object} component | ||
| * @returns {string} | ||
| */ | ||
| function getDisplayName(component) { | ||
| return component.displayName || component.name || 'Component'; | ||
| } | ||
|
|
||
| export default function (propNameToBatch, batches) { | ||
| return (WrappedComponent) => { | ||
| class withBatchedRendering extends Component { | ||
| constructor(props) { | ||
| super(props); | ||
| this.timers = []; | ||
| this.state = {}; | ||
| } | ||
|
|
||
| componentDidMount() { | ||
| _.each(batches, (batch) => { | ||
| this.timers.push( | ||
| setTimeout(() => { | ||
| this.setItemsToRender(batch.items(this.props)); | ||
| }, batch.delay || 0) | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| componentDidUpdate(prevProps) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, if I'm being honest I'm confused about why we need this function and why
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok hmm I'm trying to think of a better way to put this... Right now I have
But maybe the part you're missing is that...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I think I get it now |
||
| // We need this to allow the flow of props down from a parent component | ||
| // to work normally after all the batches have finished rendering | ||
| if (_.size(prevProps[propNameToBatch]) !== _.size(this.props[propNameToBatch])) { | ||
| this.setItemsToRender(this.props[propNameToBatch]); | ||
| } | ||
| } | ||
marcaaron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| componentWillUnmount() { | ||
| // We need to clean up any timers when the component unmounts or else | ||
| // we'll call set state on an unmounting component. | ||
| _.each(this.timers, timerID => clearTimeout(timerID)); | ||
| } | ||
|
|
||
| /** | ||
| * Sets items to the state key that matches the defined propNameToBatch | ||
| * | ||
| * @param {Object|Array} items - typically a collection of some kind | ||
| */ | ||
| setItemsToRender(items) { | ||
| this.setState({ | ||
| [propNameToBatch]: items, | ||
| }); | ||
| } | ||
|
|
||
| render() { | ||
| // We must remove the original prop that we are splitting into chunks | ||
| // since we only want our processed versions to be passed as a prop. | ||
| const propsToPass = _.omit(this.props, propNameToBatch); | ||
| return ( | ||
| <WrappedComponent | ||
| // eslint-disable-next-line react/jsx-props-no-spreading | ||
| {...propsToPass} | ||
| // eslint-disable-next-line react/jsx-props-no-spreading | ||
| {...this.state} | ||
| /> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| withBatchedRendering.displayName = `withBatchedRendering(${getDisplayName(WrappedComponent)})`; | ||
| return withBatchedRendering; | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -296,7 +296,7 @@ class ChatSwitcherView extends React.Component { | |
| } | ||
| }} | ||
| onChangeText={this.updateSearch} | ||
| onClearButtonClick={this.reset} | ||
| onClearButtonClick={() => this.reset()} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change, is it by accident?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was to fix a random error I found. not a bug or related to these changes. one of the annoying prop-types kind of errors. |
||
| onFocus={this.triggerOnFocusCallback} | ||
| onKeyPress={this.handleKeyPress} | ||
| /> | ||
|
|
||
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.
IIRC this function is the same for all our HOC's, can we DRY this up and make it a separate utility?
Uh oh!
There was an error while loading. Please reload this page.
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.
Yeah I was thinking of doing this but just left it since the proposed changes are kind of complicated and I prefer to have fewer file changes per PR if possible.
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.
Alright, it's NAB for me because this function is super simple