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

function AnuPortal(props){
    return {
        render(){
            return props.children;
        },
        componentWillUnmount(){
            console.log("弹窗被移除");
        }
    };
}

//[Top API] ReactDOM.createPortal
export function createPortal(children, node) {
    var events = node.__events || (node.__events = {});
    var vnode = createVnode(node);
    events.vnode = vnode;
    new DOMUpdater(vnode);
    var portal = createElement(AnuPortal,{children});
    vnode.portal = portal;
    return  vnode.props.children =  portal;
}
