-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmixinReactProxy.js
33 lines (31 loc) · 1.09 KB
/
mixinReactProxy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Shorter version of https://github.com/sindresorhus/object-assign/blob/master/index.js
var assign = Object.assign || function (target, source) {
var keys = Object.keys(Object(source));
for (var i=0; i<keys.length; i++) {
target[keys[i]] = source[keys[i]];
}
return target;
};
module.exports = function(React, desc) {
desc.displayName = "ReactProxy";
desc.render = function() {
var Component = this.state.component;
if(Component) {
return React.createElement(Component, assign({ref: "componentProxy"}, this.props), this.props.children);
} else if(this.renderUnavailable) {
return this.renderUnavailable();
} else {
return null;
}
};
desc.getInitialState = function() {
return { component: this.loadComponent() };
};
desc.componentDidMount = function() {
if(!this.state.component) {
this.loadComponent(function(component) {
this.setState({ component: component });
}.bind(this));
}
};
};