Skip to content

Commit a615b39

Browse files
committed
refactor: rename variables
1 parent 84d5bf9 commit a615b39

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

src/nodeOperation.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { deepClone } from './utils/index'
44
import type { Topic } from './types/dom'
55
import type { MindElixirInstance, NodeObj } from './types/index'
66
import { insertNodeObj, insertParentNodeObj, moveUpObj, moveDownObj, removeNodeObj, moveNodeObj } from './utils/objectManipulation'
7-
import { addChildDom, realAddChild, removeNodeDom } from './utils/domManipulation'
7+
import { addChildDom, removeNodeDom } from './utils/domManipulation'
88

99
const typeMap: Record<string, InsertPosition> = {
1010
before: 'beforebegin',
@@ -34,6 +34,24 @@ export const reshapeNode = function (this: MindElixirInstance, tpc: Topic, patch
3434
})
3535
}
3636

37+
const addChildFunc = function (mei: MindElixirInstance, tpc: Topic, node?: NodeObj) {
38+
if (!tpc) return null
39+
const nodeObj = tpc.nodeObj
40+
if (nodeObj.expanded === false) {
41+
mei.expandNode(tpc, true)
42+
// dom had resetted
43+
tpc = findEle(nodeObj.id) as Topic
44+
}
45+
const newNodeObj = node || mei.generateNewObj()
46+
if (nodeObj.children) nodeObj.children.push(newNodeObj)
47+
else nodeObj.children = [newNodeObj]
48+
fillParent(mei.nodeData)
49+
50+
const { grp, top: newTop } = mei.createWrapper(newNodeObj)
51+
addChildDom(mei, tpc, grp)
52+
return { newTop, newNodeObj }
53+
}
54+
3755
export const insertSibling = function (this: MindElixirInstance, type: 'before' | 'after', el?: Topic, node?: NodeObj) {
3856
const nodeEle = el || this.currentNode
3957
if (!nodeEle) return
@@ -108,7 +126,7 @@ export const addChild = function (this: MindElixirInstance, el?: Topic, node?: N
108126
console.time('addChild')
109127
const nodeEle = el || this.currentNode
110128
if (!nodeEle) return
111-
const res = addChildDom(this, nodeEle, node)
129+
const res = addChildFunc(this, nodeEle, node)
112130
if (!res) return
113131
const { newTop, newNodeObj } = res
114132
this.bus.fire('operation', {
@@ -126,7 +144,7 @@ export const copyNode = function (this: MindElixirInstance, node: Topic, to: Top
126144
console.time('copyNode')
127145
const deepCloneObj = deepClone(node.nodeObj)
128146
refreshIds(deepCloneObj)
129-
const res = addChildDom(this, to, deepCloneObj)
147+
const res = addChildFunc(this, to, deepCloneObj)
130148
if (!res) return
131149
const { newNodeObj } = res
132150
console.timeEnd('copyNode')
@@ -144,7 +162,7 @@ export const copyNodes = function (this: MindElixirInstance, tpcs: Topic[], to:
144162
const node = tpcs[i]
145163
const deepCloneObj = deepClone(node.nodeObj)
146164
refreshIds(deepCloneObj)
147-
const res = addChildDom(this, to, deepCloneObj)
165+
const res = addChildFunc(this, to, deepCloneObj)
148166
if (!res) return
149167
const { newNodeObj } = res
150168
objs.push(newNodeObj)
@@ -252,7 +270,7 @@ export const moveNodeIn = function (this: MindElixirInstance, from: Topic[], to:
252270
moveNodeObj('in', obj, toObj)
253271
fillParent(this.nodeData) // update parent property
254272
const fromTop = f.parentElement
255-
realAddChild(this, to, fromTop.parentElement)
273+
addChildDom(this, to, fromTop.parentElement)
256274
}
257275
this.linkDiv()
258276
this.bus.fire('operation', {

src/utils/domManipulation.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const judgeDirection = function (direction: number, obj: NodeObj) {
2424
}
2525
}
2626

27-
export const realAddChild = function (mei: MindElixirInstance, to: Topic, wrapper: Wrapper) {
27+
export const addChildDom = function (mei: MindElixirInstance, to: Topic, wrapper: Wrapper) {
2828
const tpc = wrapper.children[0].children[0]
2929
const top = to.parentElement
3030
if (top.tagName === 'ME-PARENT') {
@@ -48,24 +48,6 @@ export const realAddChild = function (mei: MindElixirInstance, to: Topic, wrappe
4848
}
4949
}
5050

51-
export const addChildDom = function (mei: MindElixirInstance, tpc: Topic, node?: NodeObj) {
52-
if (!tpc) return null
53-
const nodeObj = tpc.nodeObj
54-
if (nodeObj.expanded === false) {
55-
mei.expandNode(tpc, true)
56-
// dom had resetted
57-
tpc = findEle(nodeObj.id) as Topic
58-
}
59-
const newNodeObj = node || mei.generateNewObj()
60-
if (nodeObj.children) nodeObj.children.push(newNodeObj)
61-
else nodeObj.children = [newNodeObj]
62-
fillParent(mei.nodeData)
63-
64-
const { grp, top: newTop } = mei.createWrapper(newNodeObj)
65-
realAddChild(mei, tpc, grp)
66-
return { newTop, newNodeObj }
67-
}
68-
6951
export const removeNodeDom = function (tpc: Topic, siblingLength: number) {
7052
const p = tpc.parentNode
7153
if (siblingLength === 0) {

0 commit comments

Comments
 (0)