fx2y / html_first_framework

HTML-first framework
0 stars 0 forks source link

Diffing algorithm #3

Open fx2y opened 1 year ago

fx2y commented 1 year ago

for determining which parts of the DOM need to be updated.

fx2y commented 1 year ago
use virtual_dom::{Diff, Patch, VDom}

// Initialize virtual DOM from a string of HTML
let vdom = VDom::from_html("<h1>Hello, world!</h1>");

// Update the virtual DOM based on a string of HTML
let updated = VDom::from_html("<h1>Hello, world!</h1><p>This is my website.</p>");
let patches = vdom.diff(&updated);

// Apply patches to the real DOM
let container = document.get_element_by_id("app");
patches.apply(container);