fix(components/bundle): Exit early in load function (#4349)

lolsob-rspec
Sorin Davidoi 2017-07-25 01:05:44 +02:00 committed by Eugen Rochko
parent bbc0ba610b
commit 94ac88ec7f
1 changed files with 7 additions and 6 deletions

View File

@ -52,14 +52,8 @@ class Bundle extends React.Component {
load = (props) => {
const { fetchComponent, onFetch, onFetchSuccess, onFetchFail, renderDelay } = props || this.props;
this.setState({ mod: undefined });
onFetch();
if (renderDelay !== 0) {
this.timestamp = new Date();
this.timeout = setTimeout(() => this.setState({ forceRender: true }), renderDelay);
}
if (Bundle.cache[fetchComponent.name]) {
const mod = Bundle.cache[fetchComponent.name];
@ -68,6 +62,13 @@ class Bundle extends React.Component {
return Promise.resolve();
}
this.setState({ mod: undefined });
if (renderDelay !== 0) {
this.timestamp = new Date();
this.timeout = setTimeout(() => this.setState({ forceRender: true }), renderDelay);
}
return fetchComponent()
.then((mod) => {
Bundle.cache[fetchComponent.name] = mod;