import { createVnode, createElement } from "./createElement";
import { Refs } from "./Refs";
import { disposeVnode } from "./dispose";

function Portal(props) {
    this.isPortal = true;
    this.container = props.container;
}
Portal.prototype = {
    constructor: Portal,
    componentWillUnmount() {
        var root = this.container;
        
        disposeChildren(root, this.updater.updateQueue);
    },
    componentWillReceiveProps(nextProps, context) {
        var root = root;
        Refs.receiveVnode(root, nextProps.container, context, this.updater.updateQueue, []);
    },
    componentWillMount() {
        let vnode = this.container;
        vnode._disposed = true;
        Refs.mountVnode(vnode,{}, this.updater.updateQueue, [] );
        vnode._disposed = false;
    },
    render() {
        return null;
    }
};
//[Top API] ReactDOM.createPortal
export function createPortal(children, node) {
    var container = createVnode(node);
    var props = container.props;
    props.children = children;
    var portal = createElement(Portal, {
        container
    });
    container.return = portal;
    return portal;
}
