当前位置: 首页 > news >正文

网站制作将栏目分类网站设计制作公司

网站制作将栏目分类,网站设计制作公司,开封市住房和城乡建设局,旅游门户网站建设方案PortalComponent 1 )概述 React Portal之所以叫Portal,因为做的就是和“传送门”一样的事情render到一个组件里面去,实际改变的是网页上另一处的DOM结构主要关注 portal的创建, 调和, 更新过程 2 )源码 定位到 packages/react-…

PortalComponent


1 )概述

  • React Portal之所以叫Portal,因为做的就是和“传送门”一样的事情
  • render到一个组件里面去,实际改变的是网页上另一处的DOM结构
  • 主要关注 portal的创建, 调和, 更新过程

2 )源码

定位到 packages/react-dom/src/client/ReactDOM.js#L576

function createPortal(children: ReactNodeList,container: DOMContainer,key: ?string = null,
) {invariant(isValidContainer(container),'Target container is not a DOM element.',);// TODO: pass ReactDOM portal implementation as third argumentreturn ReactPortal.createPortal(children, container, null, key);
}
  • 这里调用的是 ReactPortal.createPortal, 进入

    // packages/shared/ReactPortal.js#L14
    export function createPortal(children: ReactNodeList,containerInfo: any,// TODO: figure out the API for cross-renderer implementation.implementation: any,key: ?string = null,
    ): ReactPortal {return {// This tag allow us to uniquely identify this as a React Portal$$typeof: REACT_PORTAL_TYPE,key: key == null ? null : '' + key,children,containerInfo, // dom 挂载节点implementation,};
    }
    
    • 这里返回一个对象,类似于 ReactElement
    • 区别在于 $$typeofcontainerInfo 需要的挂载点
  • 对于 REACT_PORTAL_TYPE 类型的组件在 reconcile 时, 看下具体操作, 找到 reconcileSinglePortal

    // packages/react-reconciler/src/ReactChildFiber.js#L1171
    function reconcileSinglePortal(returnFiber: Fiber,currentFirstChild: Fiber | null,portal: ReactPortal,expirationTime: ExpirationTime,
    ): Fiber {const key = portal.key; // 当前的 keylet child = currentFirstChild;// 如果 存在 child, 对比 child.key === keywhile (child !== null) {// TODO: If key === null and child.key === null, then this only applies to// the first item in the list.if (child.key === key) {// 关注这里,有 containerInfo 的对比,portal 需要关心渲染到的节点是否有变化// 如果节点有变化,那么这个 portal 的渲染过程也会有变化// 都符合,说明老节点都可以复用if (child.tag === HostPortal &&child.stateNode.containerInfo === portal.containerInfo &&child.stateNode.implementation === portal.implementation) {deleteRemainingChildren(returnFiber, child.sibling); // 删除其他节点// 通过 useFiber 复用这个节点const existing = useFiber(child,portal.children || [],expirationTime,);existing.return = returnFiber;return existing;} else {// key相同,但是不符合上述if, 没法复用,删除干净deleteRemainingChildren(returnFiber, child);break;}} else {// key 不同,删除当前节点deleteChild(returnFiber, child);}child = child.sibling;}// 创建一个 portal 的 fiber 对象const created = createFiberFromPortal(portal,returnFiber.mode,expirationTime,);created.return = returnFiber;return created;
    }
    
  • 对于更新一个portal节点,进入 updatePortalComponent

    // packages/react-reconciler/src/ReactFiberBeginWork.js#L1322
    function updatePortalComponent(current: Fiber | null,workInProgress: Fiber,renderExpirationTime: ExpirationTime,
    ) {// 挂载点处理pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);const nextChildren = workInProgress.pendingProps; // 这里 pendingProps 是 childrenif (current === null) {// Portals are special because we don't append the children during mount// but at commit. Therefore we need to track insertions which the normal// flow doesn't do during mount. This doesn't happen at the root because// the root always starts with a "current" with a null child.// TODO: Consider unifying this with how the root works.workInProgress.child = reconcileChildFibers(workInProgress,null,nextChildren,renderExpirationTime,);} else {reconcileChildren(current,workInProgress,nextChildren,renderExpirationTime,);}return workInProgress.child;
    }
    
    • 之前梳理过的 API 不再赘述
    • 一些API的调用,在源码的注释中
http://www.dinnco.com/news/29960.html

相关文章:

  • 南康网站制作友情链接怎么连
  • 做零食网站的原因如何快速搭建网站
  • 制作美食seo推广培训学费
  • 重庆网站推广多少钱百度网盘搜索引擎入口在哪里
  • 黄山网站建设找哪家福州网站开发公司
  • 上海网站推广公司排名seo关键词优化软件官网
  • 网站备案免费吗百度后台登录
  • 西安app开发软件定制百度seo怎么收费
  • 网站建设需要多少响应式网站模板的特点
  • 唐山住房城乡建设局门户网站站长工具seo综合查询怎么使用的
  • 湖北省住房与城乡建设部网站百度搜索趋势
  • 河南做网站公司哪家好优化推广
  • 陕西网站开发公司百度联盟怎么赚钱
  • 如何用web2py做网站app开发价格表
  • 网站域名与网站首页网址技成培训网
  • 中英文网站价格免费的网站推广软件下载
  • 网站下载不了怎么解决抖音推广平台
  • 怎样开发手机网站产品推广计划书怎么写
  • 做企业网站哪里找微信crm
  • dedecms织梦系统网站防会员注册机徐州seo排名公司
  • y2学年做的租房网站做网站排名优化的公司
  • wordpress开源程序建站教程如何做推广和引流
  • c#购物网站开发流程国外搜索引擎网站
  • 织梦网站标题被篡改seo网站关键词优化
  • co域名 大网站全国疫情最新情况最新消息今天
  • 做黑界头像网站网站优化排名软件
  • 吉林长春网络公司有哪些安徽seo网络推广
  • 外贸公司的网站建设模板桂林市天气预报
  • 网站视频怎么做的百度指数分析报告案例
  • 广西住房和城乡建设官方网站网站设计费用