@purtuga/dom-data-bind
Version:
DOM Data Bind utility. Bind data to DOM
77 lines (67 loc) • 2.07 kB
JavaScript
import Compose from "@purtuga/common/src/jsutils/Compose.js";
import {PRIVATE} from "../utils.js";
//============================================================
// FIXME: replace use of Compose.js
/**
* A Directive Node handler
*
* @extends Compose
*
* @param {Directive} directive Directive instance
* @param {Node} node
*/
export class NodeHandler extends Compose {
init(directive, node, directives) {
this._directives = directives;
this._d = this._directive = directive;
this._n = this._node = node;
}
/**
* List of directives that were used during parsing of the template
* @name NodeHandler#_directives
* @type Array<Directive>
*/
/**
* The Directive instance that is tied to this node handler
* @name NodeHandler#_directive
* @type Directive
* @protected
*/
/**
* The Node associated with this node handler
* @name NodeHandler#_node
* @type Node
* @protected
*/
// Override destroy (which is by default "async" and ensure that notifications
// are turned off immediately for this Node
destroy() {
const state = PRIVATE.get(this);
if (state){
if (state.tracker && state.tracker.stopWatchingAll) {
state.tracker.stopWatchingAll();
}
if (state.data) {
state.data = null;
}
}
super.destroy();
PRIVATE.delete(this);
}
/**
* Renders the data given on input to the Template.
* (By default, it proxies to the Directive#render())
*
* @param data
*/
render(data) {
this._d.render(this, this._n, data);
}
/**
* Shoudl be overwritten to contain the logic as to how a new value (generated by the Directive's `render()`)
* should be applied to the live HTML. Should be overwritten.
*
* @param {*} newValue
*/
update(/*newValue*/) {}// eslint-disable-line
}