onFetchFail: noop,
}
- static cache = {}
+ static cache = new Map
state = {
mod: undefined,
load = (props) => {
const { fetchComponent, onFetch, onFetchSuccess, onFetchFail, renderDelay } = props || this.props;
+ const cachedMod = Bundle.cache.get(fetchComponent);
onFetch();
- if (Bundle.cache[fetchComponent.name]) {
- const mod = Bundle.cache[fetchComponent.name];
-
- this.setState({ mod: mod.default });
+ if (cachedMod) {
+ this.setState({ mod: cachedMod.default });
onFetchSuccess();
return Promise.resolve();
}
return fetchComponent()
.then((mod) => {
- Bundle.cache[fetchComponent.name] = mod;
+ Bundle.cache.set(fetchComponent, mod);
this.setState({ mod: mod.default });
onFetchSuccess();
})