Skip to content

Commit

Permalink
Make <Subdivide> potentially controllable
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Oct 4, 2015
1 parent 8e4cbe8 commit fb5d352
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 32 deletions.
18 changes: 0 additions & 18 deletions src/containers/LayoutContainer.js

This file was deleted.

29 changes: 22 additions & 7 deletions src/containers/Subdivide.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, { Component } from 'react';
import { createStore } from 'redux';
import { createStore, bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import reducer from '../reducers';
import LayoutContainer from './LayoutContainer';
import Layout from '../components/Layout';
import * as LayoutActions from '../actions/LayoutActions';

function configureStore(initialState) {
let store = createStore(reducer, initialState);
Expand All @@ -16,16 +18,29 @@ function configureStore(initialState) {
return store;
}

const ConnectedLayout = connect(
state => ({ layout: state })
)(Layout);

export default class Subdivide extends Component {
constructor(props) {
super(props);
this.store = configureStore();

const {dispatch} = props;
if (dispatch) {
this.actions = bindActionCreators(LayoutActions, dispatch);
} else {
this.store = configureStore();
this.actions = bindActionCreators(LayoutActions, this.store.dispatch);
}
}

render() {
const {DefaultComponent} = this.props;
return (
<LayoutContainer DefaultComponent={DefaultComponent} store={this.store} />
);
const {store, actions} = this;
const {dispatch, ...rest} = this.props;

return store ?
<ConnectedLayout {...this.props} store={store} actions={actions} /> :
<Layout {...this.props} actions={actions} />;
}
}
10 changes: 6 additions & 4 deletions src/dev-index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
//import 'babel-core/polyfill';
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import Subdivide from './containers/Subdivide';
import Subdivide from './index';

class IframeComponent extends Component {
render() {
return (
<iframe src="index2.html" frameBorder={'0'} style={{
width: '100%',
height: '100%'
}}></iframe>
}} />
);
}
}

ReactDOM.render(<Subdivide DefaultComponent={IframeComponent}/>, document.getElementById('root'));
ReactDOM.render(
<Subdivide DefaultComponent={IframeComponent} />,
document.getElementById('root')
);

5 changes: 2 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
//import 'babel-core/polyfill';

module.exports = require('./containers/Subdivide');
export default from './containers/Subdivide';
export { default as reducer } from './reducers';

1 comment on commit fb5d352

@gaearon
Copy link
Owner Author

@gaearon gaearon commented on fb5d352 Oct 4, 2015

Choose a reason for hiding this comment

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

Usage examples: philholden#6 (comment)

Please sign in to comment.