tbranyen/diffhtml

Rewriting sync and patch

tbranyen opened this issue · 1 comments

I think diffHTML is pretty rad right now and the API is solid, but there's some imperfect logic and stability that needs correcting before 1.0. While closing in on #64 I was hitting lots of issues and code duplication with insufficient tests to safely refactor all the code with complete confidence.

So before tagging 1.0, I'll be putting my focus into rewriting both the tree synchronization (diff) and the DOM Node patching. Part of this is dramatically reducing the amount of duplicative syncing and patching logic which will bring down the lib filesize as well as thinking about each mutation operation distinctly from the ground up.

Some of the ideas I have are:

  • Removing the MODIFY_ELEMENT operation in favor of APPEND, PREPEND, REPLACE, and REMOVE. The MODIFY_ATTRIBUTE is so simple and accounts for all cases, so that will most likely stay.
  • Changing the patch from __do__ to type which aligns better with Redux actions.
  • Having a baton that carries the patches and current operation allowing for a more standardized approach to applying patches. If multiple of the same type of patch occurs, they can be batched into DocumentFragments. I'm not sure if many developers know this, but removeChild and insertBefore both support Fragments.
  • Remove REMOVE_ENTIRE_ELEMENT, REPLACE_ENTIRE_ELEMENT, and REMOVE_ELEMENT_CHILDREN in favor of the new aforementioned element operation types.
  • Writing more unit tests while refactoring so in the future this is even easier...

Closed by #107