import { EventTargetAssembler } from './eventtarget'
import { Node } from './core'

/**
 * Node DOM interface assembler
 */
export class NodeAssembler extends EventTargetAssembler {
    /**
     * @param {*} init
     * @returns {Node|*}
     */
    assemble(init) {
        if(init && init.constructor === Object && init.node instanceof Node) {
            this.init(init)
        }
        else super.assemble(init)
        return this.node
    }

    /**
     * @param {Node|*} node
     */
    set node(node) {
        const { domInterface, name } = this.constructor
        if(node instanceof domInterface) this.setInstance(node)
        else {
            const message = `Failed to set 'node' on '${ name }': parameter is not of expected type.`
            throw TypeError(message)
        }
    }

    /**
     * @returns {Node|*}
     */
    get node() {
        return this._target
    }

    /**
     * @returns {Function}
     */
    static get domInterface() {
        return Node
    }
}

@@ -335,24 +335,58 @@
 eof Node) %7B%0A
+            this.node = init.node%0A
             
@@ -397,24 +397,24 @@
 .init(init)%0A
-
         %7D%0A  
@@ -538,24 +538,61 @@
 ode(node) %7B%0A
+        if(node !== this.node) %7B%0A    
         cons
@@ -635,16 +635,20 @@
 tructor%0A
+    
         
@@ -715,15 +715,23 @@
     
+  
+  
 else %7B%0A
+    
     
@@ -840,16 +840,20 @@
         
+  
+  
 throw Ty
@@ -869,16 +869,30 @@
 essage)%0A
+            %7D%0A
         

set init.node first, don't set it twice