all files / vdom/ VFragment.js

100% Statements 24/24
100% Branches 4/4
100% Functions 5/5
100% Lines 23/23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39    717× 717× 717× 717× 717× 717×       847× 201× 646×   646× 646×     78×       708× 708× 1356×   708×     70× 70×    
import { avalon, createFragment } from '../seed/core'
 
export function VFragment(children, key, val, index) {
    this.nodeName = '#document-fragment'
    this.children = children
    this.key = key
    this.val = val
    this.index = index
    this.props = {}
}
VFragment.prototype = {
    constructor: VFragment,
    toDOM() {
        if (this.dom)
            return this.dom
        var f = this.toFragment()
            //IE6-11 docment-fragment都没有children属性 
        this.split = f.lastChild
        return this.dom = f
    },
    dispose() {
        this.toFragment()
        this.innerRender && this.innerRender.dispose()
        for (var i in this) {
            this[i] = null
        }
    },
    toFragment() {
        var f = createFragment()
        this.children.forEach(el =>
            f.appendChild(avalon.vdom(el, 'toDOM'))
        )
        return f
    },
    toHTML() {
        var c = this.children
        return c.map(el => avalon.vdom(el, 'toHTML')).join('')
    }
}