Skip to content

Commit 6650ffe

Browse files
author
user
committed
Just some ramblings on inserting and detaching
1 parent b2d9af7 commit 6650ffe

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

detach-link-notes.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
* D E F
2+
* A B C
3+
4+
`E.insertAfter(B) ->`
5+
6+
* D F
7+
* A B E C
8+
9+
* B
10+
* _next_ = C
11+
* prev = A
12+
13+
* C
14+
* next = null
15+
* _prev_ = B
16+
17+
* E
18+
* _next_ = F
19+
* _prev_ = D
20+
* _parent_ = ???
21+
22+
* D
23+
* _next_ = E
24+
* _prev_ = F
25+
26+
* F
27+
* next = null
28+
* _prev_ = E
29+
30+
italic properties must change.
31+
32+
```D
33+
// first, fix old nodes.
34+
if(E == E.parent.firstChild) // nope
35+
// E.prev must be null if this is true, short circuit logic?
36+
E.parent.firstChild = E.next;
37+
if(E == E.parent.lastChild) // nope
38+
// E.next must be null if this is true, short circuit logic?
39+
E.parent.lastChild = E.prev;
40+
if(E.next) // F
41+
E.next.prev = E.prev;
42+
if(E.prev) // D
43+
E.prev.next = E.next;
44+
// insertBefore is an exact mirror of this beyond this point, and identical before.
45+
// the links on E are free to scram now
46+
E.prev = B;
47+
E.next = B.next;
48+
49+
// now, set links to E
50+
51+
if(B.next) // C
52+
B.next.prev = E;
53+
B.next = E;
54+
```

0 commit comments

Comments
 (0)