laughinghan/mathquill — comment on commit 74bb48343ed0b72556b894a073c7ea437fc2e6d0
File:  line 0
By laughinghan:

OK, so this explains the inelegant special case you later noticed you needed: your `setNext` and `setPrev` have the right idea, but aren't quite right. `siblingify` doesn't check `prev_next` and `next_prev`, `siblingify` checks `prev` and `next` and sets `firstChild` and `lastChild`, respectively, if they're `0`. Your `setPrev` and `setNext`, using it the way you have, checks `prev_next` and `next_prev` and sets `lastChild` and `firstChild`, respectively.

I do like `setNext` and `setPrev` without the `self.next = next`, especially the part where they infer the `parent`, if you think of them as "wrappers" for `.next =` and `.prev =` that work even if `self` is 0, by inferring and modifying the `parent`! Like,

function setNext(node, next) {
if (node)
node.next = next;
else
next.parent.firstChild = next;
}

Then your `siblingify` without the `.parent` setting would be right, but we could just replace `siblingify` with that, too.