diff --git a/components/AltContainer.js b/components/AltContainer.js index 2951b5d3..f842908d 100644 --- a/components/AltContainer.js +++ b/components/AltContainer.js @@ -41,13 +41,11 @@ var React = require('react/addons') var mixinContainer = require('./mixinContainer') var assign = require('object-assign') -var cloneWithProps = React.addons.cloneWithProps - var AltContainer = React.createClass(assign({ displayName: 'AltContainer', render: function () { - return this.altRender(cloneWithProps, React.DOM.div) + return this.altRender(React.DOM.div) } }, mixinContainer(React))) diff --git a/components/AltNativeContainer.js b/components/AltNativeContainer.js index fcd035ab..1c467c5a 100644 --- a/components/AltNativeContainer.js +++ b/components/AltNativeContainer.js @@ -7,14 +7,11 @@ var React = require('react-native') var mixinContainer = require('./mixinContainer') var assign = require('object-assign') -var View = React.View -var cloneWithProps = React.cloneWithProps - var AltNativeContainer = React.createClass(assign({ displayName: 'AltNativeContainer', render: function () { - return this.altRender(cloneWithProps, View) + return this.altRender(React.View) } }, mixinContainer(React))) diff --git a/components/mixinContainer.js b/components/mixinContainer.js index 5cb1ea7f..e14fa9d9 100644 --- a/components/mixinContainer.js +++ b/components/mixinContainer.js @@ -10,6 +10,8 @@ function getStateFromKey(actions, props) { } function mixinContainer(React) { + var cloneWithProps = React.addons.cloneWithProps + return { contextTypes: { flux: React.PropTypes.object @@ -143,7 +145,7 @@ function mixinContainer(React) { : true }, - altRender: function (cloneWithProps) { + altRender: function (Node) { // Custom rendering function if (typeof this.props.render === 'function') { return this.props.render(this.getProps()) @@ -155,13 +157,13 @@ function mixinContainer(React) { // Does not wrap child in a div if we don't have to. if (Array.isArray(children)) { - return React.createElement('div', null, children.map(function (child, i) { + return React.createElement(Node, null, children.map(function (child, i) { return cloneWithProps(child, assign({ key: i }, this.getProps())) }, this)) } else if (children) { return cloneWithProps(children, this.getProps()) } else { - return React.createElement('div', this.getProps()) + return React.createElement(Node, this.getProps()) } } } diff --git a/dist/alt-with-addons.js b/dist/alt-with-addons.js index 5e0e2ff3..21201c12 100644 --- a/dist/alt-with-addons.js +++ b/dist/alt-with-addons.js @@ -50,13 +50,11 @@ var React = (typeof window !== "undefined" ? window.React : typeof global !== "u var mixinContainer = require("./mixinContainer"); var assign = require("object-assign"); -var cloneWithProps = React.addons.cloneWithProps; - var AltContainer = React.createClass(assign({ displayName: "AltContainer", render: function render() { - return this.altRender(cloneWithProps, React.DOM.div); + return this.altRender(React.DOM.div); } }, mixinContainer(React))); @@ -78,11 +76,22 @@ function getStateFromKey(actions, props) { } function mixinContainer(React) { + var cloneWithProps = React.addons.cloneWithProps; + return { contextTypes: { flux: React.PropTypes.object }, + childContextTypes: { + flux: React.PropTypes.object + }, + + getChildContext: function getChildContext() { + var flux = this.props.flux || this.context.flux; + return flux ? { flux: flux } : {}; + }, + getInitialState: function getInitialState() { if (this.props.stores && this.props.store) { throw new ReferenceError("Cannot define both store and stores"); @@ -192,7 +201,7 @@ function mixinContainer(React) { return this.props.shouldComponentUpdate ? this.props.shouldComponentUpdate(this.getProps()) : true; }, - altRender: function altRender(cloneWithProps) { + altRender: function altRender(Node) { // Custom rendering function if (typeof this.props.render === "function") { return this.props.render(this.getProps()); @@ -204,13 +213,13 @@ function mixinContainer(React) { // Does not wrap child in a div if we don't have to. if (Array.isArray(children)) { - return React.createElement("div", null, children.map(function (child, i) { + return React.createElement(Node, null, children.map(function (child, i) { return cloneWithProps(child, assign({ key: i }, this.getProps())); }, this)); } else if (children) { return cloneWithProps(children, this.getProps()); } else { - return React.createElement("div", this.getProps()); + return React.createElement(Node, this.getProps()); } } };