mframejs
Version:
simple framework
90 lines • 2.8 kB
JavaScript
export class ViewController {
constructor(htmlNode, viewController) {
this.htmlNode = htmlNode;
this.viewController = viewController;
this.count = 0;
if (viewController) {
this.viewController.addChildView(this);
}
}
searchForInstance(_customElement) {
for (const k in this.items) {
if (this.items && this.items[k]) {
if (this.items[k].classInstance) {
if (this.items[k].classInstance instanceof _customElement) {
return this.items[k].classInstance;
}
}
}
}
if (this.viewController) {
const y = this.viewController.searchForInstance(_customElement);
if (y) {
return y;
}
}
return null;
}
addElement(_class) {
this.count++;
if (!this.items) {
this.items = {};
}
this.items['e' + this.count] = _class;
}
addAttribute(attibuteController) {
this.count++;
if (!this.items) {
this.items = {};
}
this.items['a' + this.count] = attibuteController;
}
addInterpolate(interpolateController) {
this.count++;
if (!this.items) {
this.items = {};
}
this.items['i' + this.count] = interpolateController;
}
getElement() {
return this.htmlNode;
}
addChildView(viewController) {
if (!this.childViewControllers) {
this.childViewControllers = [];
}
this.childViewControllers.push(viewController);
}
removeChildView(viewController) {
if (this.childViewControllers) {
const i = this.childViewControllers.indexOf(viewController);
if (i !== -1) {
this.childViewControllers.splice(i, 1);
}
}
}
clearView() {
if (this.childViewControllers) {
while (this.childViewControllers.length) {
const view = this.childViewControllers.pop();
view.clearView();
}
}
if (this.items) {
for (const item in this.items) {
if (this.items[item].detached) {
this.items[item].detached();
this.items[item] = null;
}
}
}
if (this.viewController) {
this.viewController.removeChildView(this);
}
this.childViewControllers = null;
this.items = null;
this.htmlNode = null;
this.viewController = null;
}
}
//# sourceMappingURL=viewController.js.map