DEV Community

Discussion on: Building a Simple Virtual DOM from Scratch

 
ycmjason profile image
YCM Jason • Edited

I am sorry that my explanation didn't help. :(

diff has two base cases:

  1. If the new node is undefined
  2. If the new and old nodes are of different types. This could be either of the cases below:
    1. one of the node is a TextNode while the other one is an ElementNode
    2. Both are ElementNode but with different tag.

In fact, all my base cases are defined in a guard clause. This means that all the return statement before the last return can be considered as base case.

Thread Thread
 
ycmjason profile image
YCM Jason

Oops, I just realised there is one more, which is when there is no children in the node. But I didn't explicitly deal with that case as it will be automatically dealt with in the for loop in diffChildren