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

自己做网站原始代码/2345网址导航桌面版

自己做网站原始代码,2345网址导航桌面版,男女真实做性视频网站,空间 wordpress上两篇文章分析了初次渲染大体流程,以及创建vnode过程,都比较简单,这篇文章分析具体渲染vnode的过程。 这个render函数就是调用createAppAPI 传递过来的函数参数。在baseCreateRenderer 函数中能看到这一过程: function baseCre…

上两篇文章分析了初次渲染大体流程,以及创建vnode过程,都比较简单,这篇文章分析具体渲染vnode的过程。

这个render函数就是调用createAppAPI 传递过来的函数参数。在baseCreateRenderer 函数中能看到这一过程:

function baseCreateRenderer(options: RendererOptions,createHydrationFns?: typeof createHydrationFunctions
): any {//....//render函数在这里const render: RootRenderFunction = (vnode, container) => {if (vnode == null) {if (container._vnode) {unmount(container._vnode, null, null, true)}} else {console.log(`liubbc patch 02`)//初次渲染的时候container._vnode为undefinedpatch(container._vnode || null, vnode, container)}flushPostFlushCbs()//初次渲染后,给container对象增加一个_vnode属性,表示已为这个节点创建了vnode,下次就会进行//diff更新了container._vnode = vnode}//....return {render,hydrate,createApp: createAppAPI(render, hydrate)}}

开始patch旅程:

  const patch: PatchFn = (n1,n2,container,anchor = null,parentComponent = null,parentSuspense = null,isSVG = false,optimized = false) => {//...//从vnode中解构出type, ref, shapeFlag 进行不同的处理const { type, ref, shapeFlag } = n2switch (type) {case Text:processText(n1, n2, container, anchor)breakcase Comment:processCommentNode(n1, n2, container, anchor)break//...default:if (shapeFlag & ShapeFlags.ELEMENT) {processElement(n1,n2,container,anchor,parentComponent,parentSuspense,isSVG,optimized)} else if (shapeFlag & ShapeFlags.COMPONENT) {console.log(`liubbc processComponent 01`)//vnode的shapeFlag 是ShapeFlags.COMPONENTprocessComponent(n1,n2,container,anchor,parentComponent,parentSuspense,isSVG,optimized)} 
  const processComponent = (n1: VNode | null,n2: VNode,container: RendererElement,anchor: RendererNode | null,parentComponent: ComponentInternalInstance | null,parentSuspense: SuspenseBoundary | null,isSVG: boolean,optimized: boolean) => {if (n1 == null) {//初次渲染if (n2.shapeFlag & ShapeFlags.COMPONENT_KEPT_ALIVE) {        ;(parentComponent!.ctx as KeepAliveContext).activate(n2,container,anchor,isSVG,optimized)} else {console.log(`liubbc mountComponent 01`)// 不是keep alivemountComponent(n2,container,anchor,parentComponent,parentSuspense,isSVG,optimized)}} else {//进行diff 更新updateComponent(n1, n2, optimized)}}
  const mountComponent: MountComponentFn = (initialVNode,container,anchor,parentComponent,parentSuspense,isSVG,optimized) => {//1. 第一件事创建instanceconst instance: ComponentInternalInstance = (initialVNode.component = createComponentInstance(initialVNode,parentComponent,parentSuspense))//....//2. 第二件事安装组件setupComponent(instance)//...//3. 第三件事安装副作用函数setupRenderEffect(instance,initialVNode,container,anchor,parentSuspense,isSVG,optimized)  

走到这里patch过程就走完了,就能渲染出vnode了。mountComponent函数主要做了3件事,我们一件一件看。先看createComponentInstance过程:

export function createComponentInstance(vnode: VNode,parent: ComponentInternalInstance | null,suspense: SuspenseBoundary | null
) {const type = vnode.type as ConcreteComponent// inherit parent app context - or - if root, adopt from root vnode//如果parent为假appContext则是vnode的属性appContext所指的app对象,这个对象下有mount等方 // 法哦const appContext =(parent ? parent.appContext : vnode.appContext) || emptyAppContextconst instance: ComponentInternalInstance = {uid: uid++,vnode, //vnode属性type, //type属性parent,appContext, //appContext属性root: null!, // to be immediately setnext: null,subTree: null!, // will be set synchronously right after creationupdate: null!, // will be set synchronously right after creationrender: null, //render函数,之后会赋值template生成的render函数proxy: null,exposed: null,withProxy: null,effects: null,provides: parent ? parent.provides : Object.create(appContext.provides),accessCache: null!,renderCache: [],// local resovled assetscomponents: null,directives: null,// resolved props and emits optionspropsOptions: normalizePropsOptions(type, appContext),emitsOptions: normalizeEmitsOptions(type, appContext),// emitemit: null as any, // to be set immediatelyemitted: null,// statectx: EMPTY_OBJ,data: EMPTY_OBJ,props: EMPTY_OBJ,attrs: EMPTY_OBJ, //会赋值传过来的style对象slots: EMPTY_OBJ,refs: EMPTY_OBJ,setupState: EMPTY_OBJ,setupContext: null,// suspense relatedsuspense,suspenseId: suspense ? suspense.pendingId : 0,asyncDep: null,asyncResolved: false,// lifecycle hooks// not using enums here because it results in computed propertiesisMounted: false,isUnmounted: false,isDeactivated: false,bc: null,c: null,bm: null,m: null,bu: null,u: null,um: null,bum: null,da: null,a: null,rtg: null,rtc: null,ec: null}if (__DEV__) {instance.ctx = createRenderContext(instance)} else {//instance对象的ctx 属性对象又会指向instanceinstance.ctx = { _: instance }}instance.root = parent ? parent.root : instanceinstance.emit = emit.bind(null, instance)if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {devtoolsComponentAdded(instance)}//最后返回创建的instance对象return instance
}

createComponentInstance 方法主要是创建了instance对象,这个对象下挂载了很多属性,例如vnode下的type,vnode,appContext, render,props,attrs等,这些属性在以后渲染过程中都会用到,当然其他属性肯定也会用到,不然也不会定义了。 

最后把创建的instance对象赋值给initialVNode.component,所以下一件事就是setupComponent(instance)。

下一篇文章再分析第二件事:setupComponent(instance) 过程

http://www.lbrq.cn/news/1452673.html

相关文章:

  • 网站建设费能不能认定为广告费/搜索引擎seo如何赚钱
  • 游戏开发网/厦门谷歌seo公司
  • 政府机关单位网站建设方案/如何快速提升网站关键词排名
  • 用国外网站 图片做自媒体/专业培训seo的机构
  • 工商局网站建设查不到/小型项目外包网站
  • 学计算机网站建设/小红书外链管家
  • 广西贺州建设局网站/哈尔滨网络seo公司
  • 营销型网站建设网站建设制作/百度手机助手下载安装最新版
  • 哪个网站做漂流瓶任务/seo教程技术整站优化
  • 网站鼠标悬停动态效果代码/怎么做游戏推广员
  • 网站建设比较合理的流程/深圳关键词推广排名
  • 广州网站推广哪家好/百度网站推广怎么做
  • 茂名网站制作网页/网络平台有哪些?
  • ic外贸网站建设/百家号优化
  • 网站建设怎么添加图片上去/成都网站快速排名
  • 国外文件传输网站/网址缩短在线生成器
  • 可以建网站的软件/网页设计基础
  • 网站建设内容清单/营销网络推广哪家好
  • 怎样做一个免费的网站/内容营销策略
  • 中专网站建设与数据管理是什么/福州seo推广公司
  • 永泰县网站集约化建设/bt磁力在线种子搜索神器下载
  • 做网站要多少的服务器/网页推广怎么做的
  • 如何做镜像别人网站/php视频转码
  • 代做备案网站/百度搜索排名优化哪家好
  • 深圳网站建设机构/百度客服电话人工服务热线
  • 电子商务公司建设网站方案/互联网营销师培训多少钱
  • 设计建设网站公司网站/线上推广工作内容
  • 网站优化主要怎么做/新闻软文自助发布平台
  • 在进行网站设计时/seo人才
  • 网站规划建设与管理维护课后答案/品牌推广战略
  • 后量子时代已至?中国量子加密技术突破与网络安全新基建
  • 26-数据仓库与Apache Hive
  • FastAPI入门:安全性
  • Jupyter Notebook 中高效处理和实时展示来自 OpenCV 和 Pillow 的图像数据探究
  • 关于Web前端安全防御之内容安全策略(CSP)
  • 知识蒸馏 - 基于KL散度的知识蒸馏 HelloWorld 示例