-
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.
refactored and type script was added
- Loading branch information
Showing
11 changed files
with
492 additions
and
720 deletions.
There are no files selected for viewing
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { DcBaseComponent } from "./dc-base-component"; | ||
|
||
/** | ||
* This function returns wrapper componentClass | ||
* | ||
* @param {function} importFunction | ||
* @return {typeof DcBaseComponent} wrapper for component class | ||
*/ | ||
export const dcAsync = (importFunction: CallableFunction): any => { | ||
/** | ||
* A wrapper class for async loading | ||
* @class | ||
* @implements {DcBaseComponent} | ||
*/ | ||
class AsyncWrapper { | ||
public element: HTMLElement; | ||
public instance: DcBaseComponent; | ||
|
||
constructor(element: HTMLElement) { | ||
this.element = element; | ||
} | ||
|
||
init() { | ||
importFunction() | ||
.then(( _Class: typeof DcBaseComponent ) => { | ||
this.instance = new _Class(this.element, _Class.namespace, _Class.requiredRefs); | ||
this.instance.init(); | ||
}) | ||
.catch(error => { | ||
console.error( | ||
`An error occurred while loading the component ${importFunction}` | ||
); | ||
console.error(error); | ||
}); | ||
} | ||
|
||
destroy() { | ||
this.instance.destroy(); | ||
} | ||
} | ||
|
||
return AsyncWrapper; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.