MCPcopy Create free account
hub / github.com/Xu22Web/tech-study-js / handleChangeElement

Function handleChangeElement

tech-study.js:1868–1890  ·  view source on GitHub ↗

* @description 元素变化 * @param newEle * @param oldEle * @param comment

(newEle, oldEle, comment, subscribe, unsubscribe)

Source from the content-addressed store, hash-verified

1866 * @param comment
1867 */
1868function handleChangeElement(newEle, oldEle, comment, subscribe, unsubscribe) {
1869 if (newEle && oldEle) {
1870 const { beforeMount, onMounted } = newEle;
1871 if (beforeMount || onMounted) {
1872 subscribe && subscribe(newEle);
1873 }
1874 oldEle.ele.replaceWith(newEle.ele);
1875 return;
1876 }
1877 if (newEle && !oldEle) {
1878 const { beforeMount, onMounted } = newEle;
1879 if (beforeMount || onMounted) {
1880 subscribe && subscribe(newEle);
1881 }
1882 comment.replaceWith(newEle.ele);
1883 return;
1884 }
1885 if (!newEle && oldEle) {
1886 unsubscribe && unsubscribe(oldEle);
1887 oldEle.ele.replaceWith(comment);
1888 return;
1889 }
1890}
1891/**
1892 * @description 创建文字节点
1893 * @param text

Callers 1

handleChildrenFunction · 0.70

Calls 2

subscribeFunction · 0.70
unsubscribeFunction · 0.70

Tested by

no test coverage detected