vasille
Version:
The same framework which is designed to build bulletproof frontends (core library).
39 lines (38 loc) • 962 B
JavaScript
import { RepeatNode } from "./repeat-node.js";
/**
* Base class of default views
* @class BaseView
* @extends RepeatNode
*/
export class BaseView extends RepeatNode {
model;
/**
* Handler to catch values addition
* @type {Function}
*/
addHandler;
/**
* Handler to catch values removes
* @type {Function}
*/
removeHandler;
constructor(input, runner) {
super(input, runner);
this.model = input.model;
}
compose() {
this.addHandler = (id, item) => {
this.createChild(id, item);
};
this.removeHandler = (id, item) => {
this.destroyChild(id, item);
};
this.model.listener.onAdd(this.addHandler);
this.model.listener.onRemove(this.removeHandler);
}
destroy() {
this.model.listener.offAdd(this.addHandler);
this.model.listener.offRemove(this.removeHandler);
super.destroy();
}
}