Skip to content

Commit

Permalink
Pass in proper component to AltContainer for native
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed Apr 20, 2015
1 parent 986e50e commit cd08573
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
4 changes: 1 addition & 3 deletions components/AltContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
5 changes: 1 addition & 4 deletions components/AltNativeContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
8 changes: 5 additions & 3 deletions components/mixinContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ function getStateFromKey(actions, props) {
}

function mixinContainer(React) {
var cloneWithProps = React.addons.cloneWithProps

return {
contextTypes: {
flux: React.PropTypes.object
Expand Down Expand Up @@ -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())
Expand All @@ -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())
}
}
}
Expand Down
21 changes: 15 additions & 6 deletions dist/alt-with-addons.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)));

Expand All @@ -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");
Expand Down Expand Up @@ -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());
Expand All @@ -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());
}
}
};
Expand Down

0 comments on commit cd08573

Please sign in to comment.