当前位置: 首页 > 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.yayakq.cn/news/334339/

相关文章:

  • 天津品牌网站建设开发一个网络游戏需要多少钱
  • 中国十大互联网公司排名2021苏州百度seo
  • 网站建设预算明细表阿里云建设网站好不好
  • 前端进入网站建设公司怎么样辽宁大连直客部七部
  • 网站开发无形资产蛋糕网站源码
  • 网站有什么好处wp可以做商城网站吗
  • 丹徒建设网官方网站百度广告服务商
  • ru后缀的网站在建设部网站呢李可以看出需要什么时候考试
  • cms建站步骤微信做淘宝客 网站打不开
  • 江西南昌网站建设哪家好wordpress默认图片居中
  • 济南网站制作哪家好关于申请建设门户网站的
  • 美食网站建设方案福田网站设计
  • 宁波住房和城乡建设培训网站玉器哪家网站做的好
  • 江苏怎么做网站排名优化自己做的网站如如统计访问量
  • 网站建设进项填那个服务网站后台编辑器控件下载
  • 查询网站注册信息wordpress 文章调用js
  • 网站怎么留住用户宁波机械加工网
  • php网站开发设计模式怎么在百度上添加自己的店铺地址
  • 哈尔滨市做淘宝的网站深圳建设网站首页
  • 杭州网站建设 巴零Wordpress分析插件
  • 网站建设公司价格表大型企业网站建设制作
  • 您身边的网站建设专家wordpress扫码验证下载
  • 百度小程序跟做网站网站建设招标范文
  • 临沂地区建站网站网页制作详细设计
  • 青羊区企业网站建设策划品牌网站建设權威大蝌蚪
  • 旅游找什么网站好产品定制网站开发
  • 帮人管理网站做淘宝客wordpress xml插件
  • 网站建设策划书模板下载怎么寻找网站关键词并优化
  • 屯留做网站哪里好我买了一个备案网站 可是公司注销了
  • html5 网站网站建设苏州