import { createVnode, createElement } from "./createElement";
import { DOMUpdater } from "./DOMUpdater";

function AnuPortal(props){
    return props.children;
}

//[Top API] ReactDOM.createPortal
export function createPortal(children, node) {
    var vnode;
    if(node.__events){
        vnode = node.__events.vnode;
    }else{
        vnode = createVnode(node);
        var v = node.__events = {};
        v.vnode = vnode;
        new DOMUpdater(vnode);
        vnode.no = true;
        var p = node.parentNode;
        if(p){
            p.ddd = ture;
            var removeChild = p.removeChild;
            p.removeChild = function(){
                console.log("移除");
                removeChild.apply(this, arguments);
            };
            p.replaceChild = function(){
                console.log("replaceChild");
            };
            
        }
        console.log(!!p, p);

    }
    var ret = createElement(AnuPortal,{children});
    ret.portal = vnode;
    return ret;
}
