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

Remove unnecessary container reducer and make <Subdivide> potentially controllable #6

Merged
merged 3 commits into from
Oct 4, 2015

Conversation

gaearon
Copy link
Contributor

@gaearon gaearon commented Oct 4, 2015

This removes Container and makes layout the top-level reducer. The diff doesn't do it justice, but really all that happened is I removed Container and made what was called LayoutReducer a top-level reducer, also renaming it to be called just layout.

@gaearon
Copy link
Contributor Author

gaearon commented Oct 4, 2015

The second commit renames constants/blenderLayoutConstants to just constants/index since there don't appear any other kinds of constants.

@gaearon gaearon changed the title Remove unnecessary container reducer Remove unnecessary container reducer and make <Subdivide> potentially controllable Oct 4, 2015
@gaearon
Copy link
Contributor Author

gaearon commented Oct 4, 2015

The last commit makes reducer a named export of the package.
Now <Subdivide> acts like a chameleon:

  • If you use it directly, it will create its own store and use it;
  • If you connect() it to some part of the app's state, it will assume you have mounted the reducer there.

The reason I want these two modes is because Subdivide should be usable as is, but it would also be nice if I could mount its state to my existing reducer tree.

For example:

Normal usage

import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import Subdivide from './index';

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

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

Usage with connect()

import React, {Component} from 'react';
import {createStore, combineReducers} from 'redux';
import ReactDOM from 'react-dom';
import Subdivide, { reducer as subdivide } from './index';
import {connect, Provider} from 'react-redux';

const store = createStore(combineReducers({
  subdivide,
  // you app's reducers
}), {
  // haha! you can pass persisted state
  subdivide: {"rootId":"1","borderSize":1,"cellSpacing":3,"touchMargin":2,"width":612,"height":658,"panes":{"0":{"id":"0","childIds":[],"isGroup":false,"parentId":"1","splitRatio":0.7026143790849673,"top":0,"left":0,"width":429.99999999999994,"height":658,"joinDirection":false},"1":{"id":"1","childIds":["0","3"],"isGroup":true,"direction":"ROW","splitRatio":1,"top":0,"left":0,"width":612,"height":658},"2":{"id":"2","childIds":[],"isGroup":false,"parentId":"3","splitRatio":0.5136778115501519,"top":323,"left":432.99999999999994,"width":179.00000000000003,"height":334.99999999999994,"joinDirection":false},"3":{"id":"3","childIds":["4","2"],"isGroup":true,"direction":"COL","parentId":"1","splitRatio":0.29738562091503273,"top":0,"left":432.99999999999994,"width":179.00000000000003,"height":658,"joinDirection":false},"4":{"id":"4","childIds":[],"isGroup":false,"parentId":"3","splitRatio":0.48632218844984804,"top":0,"left":432.99999999999994,"width":179.00000000000003,"height":320,"joinDirection":false}},"dividers":{"0n3":{"id":"0n3","top":0,"left":429.99999999999994,"width":3,"height":658,"beforePaneId":"0","afterPaneId":"3","beforeRatio":0.7026143790849673,"afterRatio":0.29738562091503273,"direction":"ROW","parentSize":612},"4n2":{"id":"4n2","top":320,"left":432.99999999999994,"width":179.00000000000003,"height":3,"beforePaneId":"4","afterPaneId":"2","beforeRatio":0.48632218844984804,"afterRatio":0.5136778115501519,"direction":"COL","parentSize":658}}}
});

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

const ConnectedSubdivide = connect(
  // Tell where to grab the relevant state
  state => ({ layout: state.subdivide })
)(Subdivide);

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

gaearon referenced this pull request in gaearon/subdivide Oct 4, 2015
@philholden philholden merged commit 76c7a73 into philholden:master Oct 4, 2015
@gaearon gaearon deleted the no-root-reducer branch October 5, 2015 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants