1 | module.exports = function(React, desc) {
|
2 | desc.displayName = "ReactProxy";
|
3 | desc.render = function() {
|
4 | var Component = this.state.component;
|
5 | if(Component) {
|
6 | return React.createElement(Component, this.props, this.props.children);
|
7 | } else if(this.renderUnavailable) {
|
8 | return this.renderUnavailable();
|
9 | } else {
|
10 | return null;
|
11 | }
|
12 | };
|
13 | desc.getInitialState = function() {
|
14 | return { component: this.loadComponent() };
|
15 | };
|
16 | desc.componentDidMount = function() {
|
17 | if(!this.state.component) {
|
18 | this.loadComponent(function(component) {
|
19 | if(this.isMounted()) {
|
20 | this.setState({ component: component });
|
21 | }
|
22 | }.bind(this));
|
23 | }
|
24 | };
|
25 | };
|