From b53f834afef8f9dd7ac3864053a219d411e5fe14 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Thu, 22 Jun 2017 10:01:47 +0200 Subject: [PATCH] Removes state from Window component Resovles #9453 Auditors: @bsclifton @bbondy @bridiver Test Plan: --- app/renderer/components/window.js | 88 +++++++------------------------ js/entry.js | 2 +- 2 files changed, 20 insertions(+), 70 deletions(-) diff --git a/app/renderer/components/window.js b/app/renderer/components/window.js index 07a1b65e340..6bfa2f82c57 100644 --- a/app/renderer/components/window.js +++ b/app/renderer/components/window.js @@ -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) @@ -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, @@ -69,7 +44,7 @@ class Window extends React.Component { }) } - render () { + get classes () { let classes = {} classes['windowContainer'] = true @@ -85,50 +60,25 @@ class Window extends React.Component { classes['inactive'] = !this.windowState.getIn(['ui', 'isFocused']) } - return
-
-
+ 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
+
+
} } -Window.propTypes = { appState: PropTypes.object, frames: PropTypes.array, initWindowState: PropTypes.object } - -module.exports = Window +module.exports = ReduxComponent.connect(Window) diff --git a/js/entry.js b/js/entry.js index fd63b1c2eb0..c55bc45ce24 100644 --- a/js/entry.js +++ b/js/entry.js @@ -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( - , + , document.getElementById('appContainer')) })