Skip to content

Commit

Permalink
Merge pull request brave#8844 from brave/perf-components
Browse files Browse the repository at this point in the history
Perf components
  • Loading branch information
bsclifton authored May 12, 2017
2 parents ebfdb65 + ecc55c3 commit 7ac9acf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
8 changes: 6 additions & 2 deletions app/renderer/components/navigation/urlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,17 @@ class UrlBar extends React.Component {

select () {
if (this.urlInput) {
this.urlInput.select()
setImmediate(() => {
this.urlInput.select()
})
}
}

focus () {
if (this.urlInput) {
this.urlInput.focus()
setImmediate(() => {
this.urlInput.focus()
})
}
}

Expand Down
16 changes: 8 additions & 8 deletions app/renderer/components/reduxComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ class ReduxComponent extends ImmutableComponent {
super(props)
this.componentType = props.componentType
this.state = {}
this.internalState = props
this.checkForUpdates = debounce(this.checkForUpdates.bind(this), 5)
this.dontCheck = false
}

checkForUpdates () {
if (!this.dontCheck && this.shouldComponentUpdate(this.props, this.buildProps())) {
if (!this.dontCheck && this.shouldComponentUpdate(this.props)) {
this.forceUpdate()
}
}

componentDidMount () {
appStore.addChangeListener(this.checkForUpdates)
windowStore.addChangeListener(this.checkForUpdates)
this.internalState = this.buildProps(this.props)
}

componentWillUnmount () {
Expand All @@ -42,10 +42,6 @@ class ReduxComponent extends ImmutableComponent {
windowStore.removeChangeListener(this.checkForUpdates)
}

componentDidUpdate () {
this.internalState = this.buildProps(this.props)
}

checkParam (old, next, prop) {
return isList(next[prop])
? !isSameHashCode(next[prop], old[prop])
Expand All @@ -54,7 +50,11 @@ class ReduxComponent extends ImmutableComponent {

shouldComponentUpdate (nextProps, nextState) {
nextState = this.buildProps(nextProps)
return Object.keys(nextState).some((prop) => this.checkParam(this.internalState, nextState, prop))
const shouldUpdate = Object.keys(nextState).some((prop) => this.checkParam(this.internalState, nextState, prop))
if (shouldUpdate) {
this.internalState = nextState
}
return shouldUpdate
}

mergeProps (stateProps, dispatchProps, ownProps) {
Expand All @@ -66,7 +66,7 @@ class ReduxComponent extends ImmutableComponent {
}

render () {
return React.createElement(this.componentType, this.buildProps())
return React.createElement(this.componentType, this.internalState)
}
}

Expand Down
8 changes: 5 additions & 3 deletions app/renderer/components/tabs/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,11 @@ class Tab extends ImmutableComponent {
}

onUpdateTabSize () {
const currentSize = getTabBreakpoint(this.tabSize)
// Avoid updating breakpoint when user enters fullscreen (see #7301)
!this.props.hasTabInFullScreen && windowActions.setTabBreakpoint(this.frame, currentSize)
setImmediate(() => {
const currentSize = getTabBreakpoint(this.tabSize)
// Avoid updating breakpoint when user enters fullscreen (see #7301)
!this.props.hasTabInFullScreen && windowActions.setTabBreakpoint(this.frame, currentSize)
})
}

componentWillMount () {
Expand Down
2 changes: 1 addition & 1 deletion js/dispatcher/appDispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class AppDispatcher {
dispatchCargo.push(payload)
} else {
this.dispatching = true
this.dispatchInternal(payload, doneDispatching)
setImmediate(this.dispatchInternal.bind(this, payload, doneDispatching))
}
}

Expand Down

0 comments on commit 7ac9acf

Please sign in to comment.