import { createContainer , updateContainer , } from '../react-reconciler/ReactFiberReconciler' ; import { FiberRoot } from '../react-reconciler/ReactInternalTypes' ; import { ConcurrentRoot , LegacyRoot , RootTag , } from '../react-reconciler/ReactRootTags' ; import { ReactNodeList } from '../shared/ReactTypes' ; import { listenToAllSupportedEvents } from './events/DOMPluginEventSystem' ; import { markContainerAsRoot } from './ReactDOMComponentTree' ; import { COMMENT_NODE } from './shared/HTMLNodeType' ; export type Container = ( Element & { _reactRootContainer ? : RootType ; } ) | ( Document & { _reactRootContainer ? : RootType ; } ) ; export type RootType = { render ( children ) : void ; unmount ( ) : void ; _internalRoot : FiberRoot ; } ; /**
 * createRoot创建节点时使用的类（ConcurrentRoot）
 */ class ReactDomRoot { _internalRoot : FiberRoot ; constructor ( container ) { this . _internalRoot = createRootImpl ( container , ConcurrentRoot ) ; } render ( children ) { } unmount ( ) { } } /**
 * ReactDOM.render创建FiberRoot的时使用的类
 */ class ReactDOMLegacyRoot { _internalRoot : FiberRoot ; constructor ( container ) { this . _internalRoot = createRootImpl ( container , LegacyRoot ) ; } unmount ( ) { } render ( children ) { } } /**
 * 将JSX对象渲染为Dom并挂载到container上
 */ ReactDomRoot . prototype . render = ReactDOMLegacyRoot . prototype . render = function ( children ) { const root = this . _internalRoot ; updateContainer ( children , root ) ; } ; export const createRoot = ( container ) => { return new ReactDomRoot ( container ) ; } ; param container param tag returns const createRootImpl = ( container , tag ) : FiberRoot => { const root = createContainer ( container , tag ) ; markContainerAsRoot ( root . current , container ) ; const rootContainerElement = container . nodeType === COMMENT_NODE ? container . parentNode ! : container ; listenToAllSupportedEvents ( rootContainerElement ) ; return root ; } ; param container returns export const createLegacyRoot = ( container ) : RootType => { return new ReactDOMLegacyRoot ( container ) ; } ;