vasille
Version:
The same framework which is designed to build bulletproof frontends (core library).
38 lines (37 loc) • 876 B
JavaScript
import { Fragment } from "./node.js";
/**
* Watch Node
* @class Watch
* @extends Fragment
*/
export class Watch extends Fragment {
model;
slot;
handler;
constructor(input, runner) {
super(runner);
this.model = input.model;
this.slot = input.slot;
}
compose() {
const slot = this.slot;
if (slot) {
const handler = (this.handler = value => {
this.children.forEach(child => {
child.destroy();
});
this.children.clear();
this.lastChild = undefined;
slot(this, value);
});
this.model.on(handler);
handler(this.model.V);
}
}
destroy() {
if (this.handler) {
this.model.off(this.handler);
}
super.destroy();
}
}