UNPKG

mframejs

Version:
48 lines 1.75 kB
import { BindingEngine } from '../binding/exported'; import { Logger } from '../utils/exported'; const SubscribeInternal = class { constructor(node) { this.firstRun = true; this.name = 'Interpolate'; this.node = node; } call(newValue, oldValue) { if (oldValue !== newValue || this.firstRun) { this.firstRun = false; if (this.node.nodeType === 2) { this.node.value = newValue; } else { this.node.data = newValue; } } } }; export class InterpolateController { constructor(bindingContext, htmlNode, viewController, _isAttributeValue) { this.bindingContext = bindingContext; this.htmlNode = htmlNode; this.isAttibuteNode = false; if (!htmlNode.data) { this.isAttibuteNode = true; } this.logger = Logger.getLogger(this.isAttibuteNode ? htmlNode.value.trim() : htmlNode.data.trim(), 'interpolate'); viewController.addInterpolate(this); } init() { this.logger.log('init'); this.subscribeInternal = new SubscribeInternal(this.htmlNode); BindingEngine.subscribeClassProperty(this.bindingContext, this.isAttibuteNode ? this.htmlNode.value : this.htmlNode.data, this.subscribeInternal); } attached() { this.logger.log('attached'); } detached() { this.logger.log('detached'); BindingEngine.unSubscribeClassProperty(this.bindingContext, this.subscribeInternal); this.subscribeInternal = null; this.bindingContext = null; this.htmlNode = null; } } //# sourceMappingURL=interpolateController.js.map