atomicojs / atomico

Atomico a micro-library for creating webcomponents using only functions, hooks and virtual-dom.
https://atomicojs.dev
MIT License
1.16k stars 43 forks source link

Consider an O(ND) Difference Algorithm for DOM tree merging #8

Closed jonathantneal closed 5 years ago

jonathantneal commented 5 years ago

I tried your diffing algorithm and experienced the recreation/reloading of images and iframe elements whenever others elements were prepended before them. This can happen frequently when creating filter-able lists that contain media.

To resolve this, check out the O(ND) Difference Algorithm and Its Variations as well as these pre-optimizations. Alternatively, consider leveraging a third-party library like domdiff.

I can write a patcher for you over domdiff, but it would come in around 1.52 kB min/gzip — which isn’t too bad when domdiff is 1.5 kB min/gzip by itself.

UpperCod commented 5 years ago

Hi, Thanks for your issue, I have some questions.

  1. Was the process hydration ?, Since this is not completely complete, currently only concerns the node, but some attributes redefine it
  2. Do I use keyes?
  3. You may attach the example, I have generated a similar one in codesanbox I hope it reflects your problem

by the way the work of @WebReflection is incredible, I have analyzed its code as part of my learning

I have analyzed it and I have not used domdiff for this.

  1. HoCs : adding support for this pattern is expensive in lines of code within domdiff.
  2. management of attributes and properties: by default this does not include
  3. children: atomico treats children as React, this is to apply the default memo pattern.
  4. shadowDom: atomic allows you to apply shadowDom as an attribute, this in domdiff would break the scanning of children
  5. tag <host />, this tag is designed to facilitate work with WC.
    class Tag extends Element {
    /**❌**/
    constructor() {
        super();
        this.attachShadow({ mode: "open" });
        this.style.background = "black";
        this.addEventListener("click", () => {
            console.log("event!");
        });
    }
    /**✔️**/
    render() {
        return (
            <host
                shadowDom
                onClick={() => console.log("event")}
                style={{ background: "black" }}
            />
        );
    }
    }
UpperCod commented 5 years ago

Hi!, Identify an error in children's patching with key, adding more children in random order... It has been fixed in version 1.4.1 commit - test