2019-06-13 00:41:45 +02:00
|
|
|
import Template from "./Template.js";
|
|
|
|
|
|
|
|
export default class TemplateView {
|
2019-06-16 10:52:02 +02:00
|
|
|
constructor(vm, bindToChangeEvent) {
|
|
|
|
this.viewModel = vm;
|
|
|
|
this._changeEventHandler = bindToChangeEvent ? this.update.bind(this, this.viewModel) : null;
|
2019-06-14 22:45:13 +02:00
|
|
|
this._template = null;
|
2019-06-13 00:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
throw new Error("render not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
mount() {
|
2019-06-16 10:52:02 +02:00
|
|
|
if (this._changeEventHandler) {
|
|
|
|
this.viewModel.on("change", this._changeEventHandler);
|
|
|
|
}
|
2019-06-14 22:45:13 +02:00
|
|
|
this._template = new Template(this.viewModel, (t, value) => this.render(t, value));
|
|
|
|
return this.root();
|
2019-06-13 00:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
root() {
|
|
|
|
return this._template.root();
|
|
|
|
}
|
|
|
|
|
|
|
|
unmount() {
|
2019-06-16 10:52:02 +02:00
|
|
|
if (this._changeEventHandler) {
|
|
|
|
this.viewModel.off("change", this._changeEventHandler);
|
|
|
|
}
|
2019-06-14 22:45:13 +02:00
|
|
|
this._template.dispose();
|
|
|
|
this._template = null;
|
2019-06-13 00:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
update(value) {
|
|
|
|
this._template.update(value);
|
|
|
|
}
|
|
|
|
}
|