Closed dalyIsaac closed 5 years ago
In the deleteNode function in src/page/tree/delete.ts, yIndex is defined as a number relating to the index of y in page.nodes, and and y is defined as a node in page.nodes, as seen in https://github.com/dalyIsaac/onenote-markdown-prototype/blob/515b7fd7bd11e6677fa48c1d4c5707307be8f0de/src/page/tree/delete.ts#L211-L237
deleteNode
yIndex
y
page.nodes
Later, in the same function, https://github.com/dalyIsaac/onenote-markdown-prototype/blob/515b7fd7bd11e6677fa48c1d4c5707307be8f0de/src/page/tree/delete.ts#L280-L285
If page.nodes[yIndex] is updated to point to a new object, the reference for y will point to an old object.
page.nodes[yIndex]
Thus, in order to avoid variables not being updated, from now on do not use variables like y: Node, and rely on page.nodes[yIndex].
y: Node
The downsides are that scenarios like https://github.com/dalyIsaac/onenote-markdown-prototype/blob/515b7fd7bd11e6677fa48c1d4c5707307be8f0de/src/page/tree/delete.ts#L324
become
if (page.nodes[page.nodes[x].parent].left === x) {
where xIndex: number is replaced by x: number, and x: Node is no longer used.
xIndex: number
x: number
x: Node
This is in a similar vein to #5.
Related files:
In the
deleteNode
function in src/page/tree/delete.ts,yIndex
is defined as a number relating to the index ofy
inpage.nodes
, and andy
is defined as a node inpage.nodes
, as seen in https://github.com/dalyIsaac/onenote-markdown-prototype/blob/515b7fd7bd11e6677fa48c1d4c5707307be8f0de/src/page/tree/delete.ts#L211-L237Later, in the same function, https://github.com/dalyIsaac/onenote-markdown-prototype/blob/515b7fd7bd11e6677fa48c1d4c5707307be8f0de/src/page/tree/delete.ts#L280-L285
If
page.nodes[yIndex]
is updated to point to a new object, the reference fory
will point to an old object.Thus, in order to avoid variables not being updated, from now on do not use variables like
y: Node
, and rely onpage.nodes[yIndex]
.The downsides are that scenarios like https://github.com/dalyIsaac/onenote-markdown-prototype/blob/515b7fd7bd11e6677fa48c1d4c5707307be8f0de/src/page/tree/delete.ts#L324
become
where
xIndex: number
is replaced byx: number
, andx: Node
is no longer used.This is in a similar vein to #5.
Related files: