all files / vdom/ compact.js

100% Statements 12/12
100% Branches 8/8
100% Functions 2/2
100% Lines 12/12
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 40                                          5270×   5268× 5268× 558×   4710× 4710×          
/**
 * 虚拟DOM的4大构造器
 */
import { avalon, createFragment } from '../seed/core'
import { VText } from './VText'
import { VComment } from './VComment'
import { VElement } from './VElement'
import { VFragment } from './VFragment'
 
 
avalon.mix(avalon, {
    VText,
    VComment,
    VElement,
    VFragment
})
 
var constNameMap = {
    '#text': 'VText',
    '#document-fragment': 'VFragment',
    '#comment': 'VComment'
}
 
var vdom = avalon.vdomAdaptor = avalon.vdom = function(obj, method) {
    if (!obj) { //obj在ms-for循环里面可能是null
        return method === "toHTML" ? '' : createFragment()
    }
    var nodeName = obj.nodeName
    if (!nodeName) {
        return (new avalon.VFragment(obj))[method]()
    }
    var constName = constNameMap[nodeName] || 'VElement'
    return avalon[constName].prototype[method].call(obj)
}
 
avalon.domize = function(a) {
    return avalon.vdom(a, 'toDOM')
}
 
export { vdom, avalon, VText, VComment, VElement, VFragment }