Docs
Virtual DOM
Extra
morph()

morph()

Syntax: morph(newDOMNode, prevDOMNode, hook = (el?, newVNode?, oldVNode?) => boolean)
Example: morph('<div>Hello World</div>', document.createElement('div'))

The morph function updates the DOM content by determining pinpoint changes through diffing a new DOM node with an old DOM node. It accepts two HTMLElement or Text. It also returns the resulting HTMLElement or Text.

import { m, patch, createElement } from 'million';
 
const refNode = document.createElement('div');
const newNode = document.createElement('div');
newNode.textContent = 'Hello World';
 
document.body.appendChild(refNode);
 
morph(newNode, refNode); // <div></div> -> <div>Hello World</div>
 
morph('<div>Goodbye World</div>', refNode); // <div>Hello World</div> -> <div>Goodbye World</div>
Last updated on September 5, 2022