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

Redux: Provide Redux store instance to Layout component #1800

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions client/boot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ function init() {
} );
}

function setUpContext( layout ) {
var reduxStore = createReduxStore();

function setUpContext( layout, reduxStore ) {
// Pass the layout so that it is available to all page handlers
// and add query and hash objects onto context object
page( '*', function( context, next ) {
Expand Down Expand Up @@ -140,6 +138,7 @@ function loadDevModulesAndBoot() {

function boot() {
var layoutSection, layout, validSections = [];
var reduxStore = createReduxStore();

init();

Expand All @@ -163,6 +162,7 @@ function boot() {
// Create layout instance with current user prop
Layout = require( 'layout' );
layout = ReactDom.render( React.createElement( Layout, {
store: reduxStore,
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont know if we really need that - we can connect components that need access to store using connect down the line.

user: user,
sites: sites,
focus: layoutFocus,
Expand Down Expand Up @@ -194,7 +194,7 @@ function boot() {
window.history.replaceState( null, document.title, window.location.pathname );
}

setUpContext( layout );
setUpContext( layout, reduxStore );
Copy link
Contributor

Choose a reason for hiding this comment

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

Had to do the same :)


page( '*', require( 'lib/route/normalize' ) );

Expand Down
10 changes: 9 additions & 1 deletion client/layout/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var React = require( 'react' ),
property = require( 'lodash/utility/property' ),
sortBy = require( 'lodash/collection/sortBy' );

import { Provider } from 'react-redux';

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -99,7 +101,7 @@ module.exports = React.createClass( {
sectionClass += ' has-no-sidebar';
}

return (
const layout = (
<div className={ sectionClass }>
{ config.isEnabled( 'keyboard-shortcuts' ) ? <KeyboardShortcutsMenu /> : null }
<Masterbar user={ this.props.user } section={ this.state.section } sites={ this.props.sites }/>
Expand All @@ -121,5 +123,11 @@ module.exports = React.createClass( {
isActive={ translator.isActivated() }/>
</div>
);

return (
<Provider store={ this.props.store }>
Copy link
Contributor

Choose a reason for hiding this comment

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

You will have problems with everything that uses context.layout.setState, because it will set the state of Provider, not Layout, thats why I moved those state values to store and connected all of it.

Copy link
Contributor

Choose a reason for hiding this comment

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

{ layout }
</Provider>
);
}
} );