Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Removes state from Window component
Browse files Browse the repository at this point in the history
Resovles #9453

Auditors: @bsclifton @bbondy @bridiver

Test Plan:
  • Loading branch information
NejcZdovc committed Jun 22, 2017
1 parent f3efaa1 commit b53f834
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 70 deletions.
88 changes: 19 additions & 69 deletions app/renderer/components/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,30 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

// Controller view which manages the top level immutable state for the app

const React = require('react')
const PropTypes = require('prop-types')
const Immutable = require('immutable')

// Components
const Main = require('./main/main')

// Stores
const windowStore = require('../../../js/stores/windowStore')
const appStoreRenderer = require('../../../js/stores/appStoreRenderer')
const ReduxComponent = require('./reduxComponent')

// Actions
const windowActions = require('../../../js/actions/windowActions')
const appActions = require('../../../js/actions/appActions')

// Utils
const cx = require('../../../js/lib/classSet')
const frameStateUtil = require('../../../js/state/frameStateUtil')
const {getPlatformStyles} = require('../../common/lib/platformUtil')
const {getCurrentWindowId} = require('../currentWindow')

window.appActions = appActions

class Window extends React.Component {
constructor (props) {
super(props)
// initialize appState from props
// and then listen for updates
this.appState = appStoreRenderer.state
this.windowState = Immutable.fromJS(this.props.initWindowState) || windowStore.getState()
this.state = {
immutableData: {
windowState: this.windowState,
appState: this.appState
}
}
if (this.props.initWindowState) {
windowActions.setState(this.windowState)
}

this.onChange = this.onChange.bind(this)
this.onAppStateChange = this.onAppStateChange.bind(this)
windowStore.addChangeListener(this.onChange)
appStoreRenderer.addChangeListener(this.onAppStateChange)
componentDidMount () {
appActions.windowReady(getCurrentWindowId())
}

componentWillMount () {
const activeFrameKey = this.state.immutableData.windowState.get('activeFrameKey')
this.props.frames.forEach((frame, i) => {
if (frame.guestInstanceId) {
appActions.newWebContentsAdded(getCurrentWindowId(), frame)
Expand All @@ -59,7 +34,7 @@ class Window extends React.Component {
url: frame.location || frame.src || frame.provisionalLocation,
partitionNumber: frame.partitionNumber,
isPrivate: frame.isPrivate,
active: activeFrameKey ? frame.key === activeFrameKey : true,
active: this.props.activeFrameKey ? frame.key === this.props.activeFrameKey : true,
discarded: frame.unloaded,
title: frame.title,
faviconUrl: frame.icon,
Expand All @@ -69,7 +44,7 @@ class Window extends React.Component {
})
}

render () {
get classes () {
let classes = {}
classes['windowContainer'] = true

Expand All @@ -85,50 +60,25 @@ class Window extends React.Component {
classes['inactive'] = !this.windowState.getIn(['ui', 'isFocused'])
}

return <div id='windowContainer' className={cx(classes)} >
<Main windowState={this.state.immutableData.windowState}
appState={this.state.immutableData.appState} />
</div>
return classes
}

componentDidMount () {
appActions.windowReady(getCurrentWindowId())
}
mergeProps (state, ownProps) {
const currentWindow = state.get('currentWindow')
const activeFrame = frameStateUtil.getActiveFrame(currentWindow) || Immutable.Map()

componentWillUnmount () {
windowStore.removeChangeListener(this.onChange)
appStoreRenderer.removeChangeListener(this.onAppStateChange)
}

shouldComponentUpdate (nextProps, nextState) {
return nextState.immutableData !== this.state.immutableData
}
const props = {}
props.activeFrameKey = activeFrame.get('key')
props.frames = ownProps.frames

onChange () {
setImmediate(() => {
this.windowState = windowStore.getState()
this.setState({
immutableData: {
windowState: this.windowState,
appState: this.appState
}
})
})
return props
}

onAppStateChange () {
setImmediate(() => {
this.appState = appStoreRenderer.state
this.setState({
immutableData: {
windowState: this.windowState,
appState: this.appState
}
})
})
render () {
return <div id='windowContainer' className={cx(this.classes)} >
<Main />
</div>
}
}

Window.propTypes = { appState: PropTypes.object, frames: PropTypes.array, initWindowState: PropTypes.object }

module.exports = Window
module.exports = ReduxComponent.connect(Window)
2 changes: 1 addition & 1 deletion js/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ ipc.on(messages.INITIALIZE_WINDOW, (e, windowValue, appState, frames, initWindow
currentWindow.setWindowId(windowValue.id)
appStoreRenderer.state = Immutable.fromJS(appState)
ReactDOM.render(
<Window frames={frames} initWindowState={initWindowState} />,
<Window frames={frames} />,
document.getElementById('appContainer'))
})

0 comments on commit b53f834

Please sign in to comment.