MCPcopy Index your code
hub / github.com/Xu22Web/tech-study-js / createElementNode

Function createElementNode

tech-study.js:1308–1361  ·  view source on GitHub ↗

* @description 创建元素节点 * @param eleName * @param props * @param attrs * @param children * @returns

(tagName, props, attrs, children, options)

Source from the content-addressed store, hash-verified

1306 * @returns
1307 */
1308function createElementNode(tagName, props, attrs, children, options) {
1309 // 挂载状态
1310 let beforemount = ref(false);
1311 // 挂载状态
1312 let mounted = ref(false);
1313 const { onCreated, beforeCreat, onMounted, beforeMount } = options || {};
1314 // 订阅
1315 const subscribe = (e) => {
1316 const { onMounted, beforeMount } = e;
1317 if (beforeMount) {
1318 watch(beforemount, () => {
1319 if (beforemount.value) {
1320 beforeMount();
1321 return;
1322 }
1323 }, true);
1324 }
1325 if (onMounted) {
1326 watch(mounted, () => {
1327 if (mounted.value) {
1328 onMounted();
1329 return;
1330 }
1331 }, true);
1332 }
1333 };
1334 // 取消订阅
1335 const unsubscribe = (e) => {
1336 //懒得写
1337 };
1338 // 创建元素前
1339 beforeCreat && beforeCreat();
1340 // 创建普通元素
1341 const ele = document.createElement(tagName);
1342 // 处理属性
1343 handleProps(ele, props);
1344 // 处理属性
1345 handleAttributes(ele, attrs, subscribe, unsubscribe);
1346 // 处理子元素
1347 handleChildren(ele, children, subscribe, unsubscribe);
1348 // 收集挂载前
1349 const collectBeforeMount = () => {
1350 beforemount.value = true;
1351 beforeMount && beforeMount();
1352 };
1353 // 收集挂载
1354 const collectOnMounted = () => {
1355 mounted.value = true;
1356 onMounted && onMounted();
1357 };
1358 // 创建元素后
1359 onCreated && onCreated();
1360 return { ele, beforeMount: collectBeforeMount, onMounted: collectOnMounted };
1361}
1362/**
1363 * @description 创建svg元素
1364 * @param tagName

Callers 15

renderTipFunction · 0.70
TipFunction · 0.70
HrFunction · 0.70
SelectFunction · 0.70
ExamBtnFunction · 0.70
FrameFunction · 0.70
LoginItemFunction · 0.70
InfoItemFunction · 0.70
ScoreItemFunction · 0.70
NomalItemFunction · 0.70
TaskItemFunction · 0.70
TaskListFunction · 0.70

Calls 4

refFunction · 0.70
handlePropsFunction · 0.70
handleAttributesFunction · 0.70
handleChildrenFunction · 0.70

Tested by

no test coverage detected