src/template.js
function getNodesMetaData(rootEl) {
    let elMeta = [];

    let toVisit = [rootEl];
    let current = {el: rootEl, path: [], isPre: $.tag(rootEl) === 'PRE'};

    //generate paths for comment and text nodes. There's no way to quickly retrieve them
    //need to deeply traverse the DOM tree
    while (current) {
        let {el, isPre, path} = current;
        let childNodes = $.childNodes(el);

        for (let i = 0; i < childNodes.length; i++) {
            let childNode = childNodes[i];

            if ($.isText(childNode)) {
                let {meta, delta} = getTextMetaData(rootEl, i, childNode, path, !isPre);
                elMeta.push(...meta);
                i += delta;
            } else if ($.isElement(childNode)) {
                let name = $.getAttr(childNode, ATTR);
                if (name && $.tag(childNode) === 'SCRIPT') {
                    let {meta, delta} = getContainerMetaData(rootEl, i, childNode, path, name);
                    elMeta.push(...meta);
                    i += delta;
                } else {
                    toVisit.push({
                        el: childNode,
                        path: path.concat(i),
                        isPre: current.isPre || $.tag(childNode) === 'PRE'
                    });
                }
            }
        }

        toVisit.shift();
        current = toVisit[0];
    }

    let elementMeta = getElementsMetaData(rootEl);
    elMeta.push(...elementMeta);

    //we need to sort the elements in order of their depth, so that they can be updated
    //from bottom up when ultimately passed to a component.
    return elMeta.sort((a, b) => b.depth - a.depth);
}
function getNodesMetaData(rootEl) {
    let elMeta = [];

    let toVisit = [rootEl];
    let current = {el: rootEl, path: [], isPre: $.tag(rootEl) === 'PRE'};

    //generate paths for comment and text nodes. There's no way to quickly retrieve them
    //need to deeply traverse the DOM tree
    while (current) {
        let {el, isPre, path} = current;
        let childNodes = $.childNodes(el);

        for (let i = 0; i < childNodes.length; i++) {
            let childNode = childNodes[i];

            if ($.isText(childNode)) {
                let {meta, delta} = getTextMetaData(rootEl, i, childNode, path, !isPre);
                elMeta.push(...meta);
                i += delta;
            } else if ($.isElement(childNode)) {
                let name = $.getAttr(childNode, ATTR);
                if (name && $.tag(childNode) === 'SCRIPT') {
                    let {meta, delta} = getContainerMetaData(rootEl, i, childNode, path, name);
                    elMeta.push(...meta);
                    i += delta;
                } else {
                    toVisit.push({
                        el: childNode,
                        path: path.concat(i),
                        isPre: current.isPre || $.tag(childNode) === 'PRE'
                    });
                }
            }
        }

        toVisit.shift();
        current = toVisit[0];
    }

    let elementMeta = getElementsMetaData(rootEl);
    elMeta.push(...elementMeta);

    //we need to sort the elements in order of their depth, so that they can be updated
    //from bottom up when ultimately passed to a component.
    return elMeta.sort((a, b) => b.depth - a.depth);
}
function getNodesMetaData ( rootEl ) { let elMeta = [ ] ; let toVisit = [ rootEl ] ; let current = { el : rootEl , path : [ ] , isPre : $ . tag ( rootEl ) === 'PRE' } ; //generate paths for comment and text nodes. There's no way to quickly retrieve them //need to deeply traverse the DOM tree while ( current ) { let { el , isPre , path } = current ; let childNodes = $ . childNodes ( el ) ; for ( let i = 0 ; i < childNodes . length ; i ++ ) { let childNode = childNodes [ i ] ; if ( $ . isText ( childNode ) ) { let { meta , delta } = getTextMetaData ( rootEl , i , childNode , path , ! isPre ) ; elMeta . push ( ... meta ) ; i += delta ; } else if ( $ . isElement ( childNode ) ) { let name = $ . getAttr ( childNode , ATTR ) ; if ( name && $ . tag ( childNode ) === 'SCRIPT' ) { let { meta , delta } = getContainerMetaData ( rootEl , i , childNode , path , name ) ; elMeta . push ( ... meta ) ; i += delta ; } else { toVisit . push ( { el : childNode , path : path . concat ( i ) , isPre : current . isPre || $ . tag ( childNode ) === 'PRE' } ) ; } } } toVisit . shift ( ) ; current = toVisit [ 0 ] ; } let elementMeta = getElementsMetaData ( rootEl ) ; elMeta . push ( ... elementMeta ) ; //we need to sort the elements in order of their depth, so that they can be updated //from bottom up when ultimately passed to a component. return elMeta . sort ( ( a , b ) => b . depth - a . depth ) ; }
gather meta data from a DOM element template. Only runs once per template and the resulting data can be applied to any cloned template. Primarly used to generate paths to non-static nodes within a cloned template.
gather meta data from a DOM element template . Only runs once per template and the resulting data can be applied to any cloned template . Primarly used to generate paths to non - static nodes within a cloned template .