2.0.0 ⢠Published 5 months ago
flyweight-dom v2.0.0
npm install --save-prod flyweight-dom
The extremely fast DOM implementation.
- DOM can be extended with custom nodes;
- Low memory consumption;
- Zero dependencies;
- 4 kB gzipped.
Usage
š API documentation is available here.
The implementation provides classes for all DOM nodes:
import { Element } from 'flyweight-dom';
const element = new Element('div').append(
'Hello, ',
new Element('strong').append('world!')
);
element.classList.add('red');
element.getAttribute('class');
// ā® 'red'
Performance considerations
For better performance, prefer nextSibling
and previousSibling
over childNodes
and children
whenever possible.
for (let child = node.firstChild; child !== null; child = child.nextSibling) {
// Process the child
}
When you read the childNodes
or children
properties for the first time an array of nodes is created and then stored
on the node instance. Later when you modify child nodes using appendChild
, removeChild
or any other method, these
arrays are updated which may introduce a performance impact.