Skip to content

Commit

Permalink
refactored and type script was added
Browse files Browse the repository at this point in the history
  • Loading branch information
Ofigelov committed Oct 19, 2020
1 parent dab82ff commit efe4602
Show file tree
Hide file tree
Showing 11 changed files with 492 additions and 720 deletions.
50 changes: 0 additions & 50 deletions src/dc-async.js

This file was deleted.

43 changes: 43 additions & 0 deletions src/dc-async.ts
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;
}
208 changes: 0 additions & 208 deletions src/dc-base-component.js

This file was deleted.

Loading

0 comments on commit efe4602

Please sign in to comment.