hooks port to domBinding

This commit is contained in:
Kevin Jahns
2018-04-26 13:26:21 +02:00
parent 94933a704d
commit 1fe37c565e
9 changed files with 68 additions and 51 deletions

View File

@@ -30,6 +30,9 @@ export default class DomBinding extends Binding {
constructor (type, target, opts = {}) {
// Binding handles textType as this.type and domTextarea as this.target
super(type, target)
this.opts = opts
opts.document = opts.document || document
opts.hooks = opts.hooks || {}
/**
* Maps each DOM element to the type that it is associated with.
* @type {Map}
@@ -49,11 +52,11 @@ export default class DomBinding extends Binding {
// set initial value
target.innerHTML = ''
for (let child of type) {
target.insertBefore(child.toDom(this.domToType, this.typeToDom), null)
target.insertBefore(child.toDom(opts.document, opts.hooks, this), null)
}
this._typeObserver = typeObserver.bind(this)
this._domObserver = (mutations) => {
domObserver.call(this, mutations, opts._document)
domObserver.call(this, mutations, opts.document)
}
type.observeDeep(this._typeObserver)
this._mutationObserver = new MutationObserver(this._domObserver)