-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Ability to async loading the component chunk * Introduce Component interface * Updated documentation
- Loading branch information
1 parent
06966d0
commit 01d5970
Showing
7 changed files
with
162 additions
and
32 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import DcBaseComponent from './dc-base-component'; | ||
import dcFactory from './dc-factory'; | ||
|
||
/** | ||
* This function returns wrapper componentClass | ||
* | ||
* @param {function} importFunction | ||
* @param {string} nameSpace | ||
* @return {typeof Component} wrapper for component class | ||
*/ | ||
export default function dcDeferredLoading(importFunction, nameSpace) { | ||
/** | ||
* A wrapper class for deferred loading | ||
* @class | ||
* @implements {Component} | ||
*/ | ||
class DeferredWrapper { | ||
constructor(element) { | ||
this.element = element; | ||
} | ||
|
||
getElement() { | ||
return this.element; | ||
} | ||
|
||
init() { | ||
importFunction() | ||
.then(({ default: componentClass }) => { | ||
this.actualInstance = new componentClass(this.element); | ||
this.actualInstance.init(); | ||
}) | ||
.catch(error => { | ||
console.error( | ||
`An error occurred while loading the component ${nameSpace}` | ||
); | ||
console.error(error); | ||
}); | ||
} | ||
|
||
destroy() { | ||
this.actualInstance.destroy(); | ||
} | ||
|
||
static getNamespace() { | ||
return nameSpace; | ||
} | ||
} | ||
|
||
return DeferredWrapper; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import DcBaseComponent from './dc-base-component'; | ||
import dcFactory from './dc-factory'; | ||
import dcDom from './dc-dom'; | ||
import dcDeferredLoading from './dc-deferred-loading'; | ||
|
||
export { | ||
DcBaseComponent, | ||
dcFactory, | ||
dcDom | ||
dcDom, | ||
dcDeferredLoading | ||
} |