preact原始碼學習(4)

2021-09-16 14:26:22 字數 1461 閱讀 6430

這節開始說**機制。在這之前把元件的最後一點內容收尾。buildcomponentfromvnode相當於updatecomponent, 但裡面存在替換操作。在替換過程一堆銷毀函式出現了。

recollectnodetree

unmountcomponent

removechildren

removenode

export function buildcomponentfromvnode(dom, vnode, context, mountall) 

//如果能找到這個例項,並且不是在reactdom.render過程中

if (c && isowner && (!mountall || c._component))

else

c = createcomponent(vnode.nodename, props, context);

if (dom && !c.nextbase)

setcomponentprops(c, props, sync_render, context, mountall);

dom = c.base;

if (olddom && dom!==olddom)

}return dom;

}

unmountcomponent是乙個遞迴處理子元件的過程

export function unmountcomponent(component) 

else if (base)

//處理元件自身的ref,如}>

if (component.__ref) component.__ref(null);

}

removenode是將節點從它的父節點中分離出來

export function removenode(node)
下面是removechildren與recollectnodetree,removechildren其實是個二道販子,只是負責遍歷,真正做的事的是recollectnodetree。

export function removechildren(node) 

}//recollectnodetree用於移除元件與執行元素節點的快取資料

export function recollectnodetree(node, unmountonly)

else

removechildren(node);

}}

至此,銷毀部分已經講完了,還剩下diffattributes及其內部實現。這個沒有什麼好談,都是巨簡單,裡面盡是if else。

總評,preact其實從它這樣體量的**,許多情況是兼顧不及的。唯一稱道的是效能。為了達成這效能,它盡量使用非同步與_disable來控制項的更新。為了確保資料不會亂,它是根據頁面的真實dom上來提取現有的虛擬dom樹進行diff。

HBase 原始碼學習 Flush(4)

根據前三篇文章,hbase flush主要分三個階段,snapshot,flush,commit,這篇深入hbase memstore,梳理snapshot的流程。volatile section activesection volatile section snapshotsection mems...

Vue原始碼學習(4) 資料響應系統

watcher在 vm.mount vm.options.el function definereactive obj,key,val return val set function newval val newval dep.notify 發布改變 class dep addsub sub rem...

筆記4 讀原始碼

好吧,截圖都沒了。就這把,內容很具體,跟著操作完全沒問題。系統設定中可看到關於手機容量的資訊,我們只要找到setting的原始碼,就能找到android系統是怎麼做到的。注意adt安裝目錄下的sdk sources目錄裡並不是android系統的原始碼,而是用到的jar包的原始碼。原始碼資料夾 bu...