Top Related Projects
The library for web and native user interfaces.
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
Deliver web apps with confidence 🚀
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
Cybernetically enhanced web apps
Quick Overview
Incremental DOM is a library for building up and updating the DOM efficiently. It provides a way to define templates for rendering HTML, and then efficiently update those templates as the underlying data changes.
Pros
- Efficient DOM Updates: Incremental DOM only updates the parts of the DOM that have changed, reducing unnecessary reflows and repaints.
- Declarative Syntax: The library provides a declarative syntax for defining templates, making it easier to reason about the structure of the UI.
- Small Footprint: Incremental DOM has a small footprint, with a gzipped size of around 6KB.
- Framework-Agnostic: Incremental DOM can be used with any JavaScript framework or library, or even without a framework at all.
Cons
- Learning Curve: Incremental DOM has a different programming model than traditional DOM manipulation, which may require a learning curve for some developers.
- Limited Ecosystem: Compared to more popular frameworks like React or Angular, Incremental DOM has a smaller ecosystem of third-party libraries and tooling.
- Lack of Widespread Adoption: Incremental DOM has not achieved the same level of widespread adoption as some other popular front-end frameworks.
- Potential Performance Issues: While Incremental DOM is generally efficient, it may not always outperform other approaches, especially in complex or highly dynamic applications.
Code Examples
Here are a few examples of how to use Incremental DOM:
Defining a Template:
function render(data) {
elementOpen('div', null, null);
text(data.message);
elementClose('div');
}
This function defines a simple template that renders a <div>
element with the message from the data
object.
Updating the DOM:
const container = document.getElementById('container');
patch(container, () => render({ message: 'Hello, Incremental DOM!' }));
This code updates the DOM by calling the patch
function, which efficiently updates the container element with the new data.
Handling Events:
function handleClick(event) {
console.log('Button clicked!');
}
function render(data) {
elementOpen('button', null, ['onclick', handleClick]);
text('Click me');
elementClose('button');
}
This example shows how to attach event handlers to elements in an Incremental DOM template.
Getting Started
To get started with Incremental DOM, you can follow these steps:
- Install the library using npm or a CDN:
npm install incremental-dom
- Import the necessary functions from the library:
import { elementOpen, elementClose, text, patch } from 'incremental-dom';
- Define your templates using the Incremental DOM functions:
function render(data) {
elementOpen('div', null, null);
text(data.message);
elementClose('div');
}
- Update the DOM by calling the
patch
function:
const container = document.getElementById('container');
patch(container, () => render({ message: 'Hello, Incremental DOM!' }));
That's the basic workflow for using Incremental DOM. You can find more detailed documentation and examples on the Incremental DOM GitHub repository.
Competitor Comparisons
The library for web and native user interfaces.
Pros of React
- Extensive ecosystem with a large community and a wide range of third-party libraries and tools
- Powerful and flexible component-based architecture, allowing for modular and reusable UI development
- Efficient virtual DOM implementation, which minimizes unnecessary DOM updates and improves performance
Cons of React
- Larger bundle size due to the inclusion of the React library and additional dependencies
- Steeper learning curve compared to Incremental DOM, especially for developers new to the React ecosystem
Code Comparison
React:
function MyComponent(props) {
return (
<div>
<h1>{props.title}</h1>
<p>{props.content}</p>
</div>
);
}
Incremental DOM:
function MyComponent(props) {
elementOpen('div');
elementOpen('h1');
text(props.title);
elementClose('h1');
elementOpen('p');
text(props.content);
elementClose('p');
elementClose('div');
}
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
Pros of Vue
- Vue provides a more comprehensive and opinionated framework, with features like virtual DOM, reactive data binding, and a component-based architecture.
- Vue has a larger and more active community, with a wealth of third-party libraries and tools available.
- Vue's learning curve is generally considered more beginner-friendly compared to Incremental DOM.
Cons of Vue
- Vue is a larger and more complex framework, which may be overkill for some simpler use cases.
- Vue's ecosystem is more fragmented, with a wider range of libraries and tools to choose from, which can be overwhelming for new users.
- Vue's performance, while generally good, may not be as optimized as Incremental DOM for certain low-level DOM operations.
Code Comparison
Incremental DOM (5 lines):
function render(data) {
patch(null, () => {
elementOpen('div');
text(data.message);
elementClose('div');
});
}
Vue (5 lines):
<template>
<div>{{ message }}</div>
</template>
<script>
export default {
data() {
return {
message: 'Hello, World!'
}
}
}
</script>
Deliver web apps with confidence 🚀
Pros of Angular
- Angular provides a comprehensive framework with a rich set of features, including a powerful templating system, dependency injection, and a robust routing system.
- Angular has a large and active community, with extensive documentation, tooling, and third-party libraries available.
- Angular's TypeScript-based approach offers better type safety and tooling support compared to Incremental DOM's JavaScript-based implementation.
Cons of Angular
- Angular has a steeper learning curve compared to Incremental DOM, which may be more suitable for smaller projects or developers with less experience.
- Angular's size and complexity can make it overkill for simple or lightweight applications, where Incremental DOM's smaller footprint may be more appropriate.
Code Comparison
Incremental DOM
function render(data) {
elementOpen('div', null, null);
text(data.message);
elementClose('div');
}
Angular
@Component({
selector: 'app-my-component',
template: '<div>{{ data.message }}</div>'
})
export class MyComponent {
data = { message: 'Hello, World!' };
}
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
Pros of Preact
- Preact is a lightweight (3kB gzipped) alternative to React, with a similar API, making it easy to migrate existing React projects.
- Preact has a faster initial load time and better performance compared to React, especially for smaller applications.
- Preact has a simpler and more focused codebase, making it easier to understand and contribute to.
Cons of Preact
- Preact has a smaller ecosystem compared to React, with fewer third-party libraries and plugins available.
- Preact may not have the same level of community support and documentation as React, which can make it more challenging for new developers to get started.
- Preact may not be as feature-rich as React, with some advanced features and functionality missing.
Code Comparison
Incremental DOM:
function render(data) {
patch(document.body, () => {
div({}, [
h1({}, data.title),
p({}, data.content)
]);
});
}
Preact:
function render(data) {
render(
<div>
<h1>{data.title}</h1>
<p>{data.content}</p>
</div>,
document.body
);
}
Cybernetically enhanced web apps
Pros of Svelte
- Svelte is a reactive framework, which means that it automatically updates the DOM when the underlying data changes, reducing the need for manual DOM manipulation.
- Svelte has a simple and intuitive syntax, making it easier to learn and use compared to more complex frameworks like React or Angular.
- Svelte is highly performant, as it compiles your components into highly optimized JavaScript code that minimizes the amount of DOM updates.
Cons of Svelte
- Svelte has a smaller ecosystem compared to more established frameworks like React or Angular, which means fewer third-party libraries and tools available.
- Svelte's compilation-based approach can make it more difficult to debug issues, as the compiled code may not be as straightforward to understand as the original Svelte code.
Code Comparison
Incremental DOM (Google):
function render(data) {
patch(null, () => {
elementOpen('div');
text('Hello, ');
elementOpen('span');
text(data.name);
elementClose('span');
text('!');
elementClose('div');
});
}
Svelte:
<script>
export let name;
</script>
<div>
Hello, <span>{name}!</span>
</div>
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Incremental DOM
Overview
Incremental DOM is a library for building up DOM trees and updating them in-place when data changes. It differs from the established virtual DOM approach in that no intermediate tree is created (the existing tree is mutated in-place). This approach significantly reduces memory allocation and GC thrashing for incremental updates to the DOM tree therefore increasing performance significantly in some cases.
Incremental DOM is primarily intended as a compilation target for templating languages. It could be used to implement a higher level API for human consumption. The API was carefully designed to minimize heap allocations and where unavoidable ensure that as many objects as possible can be de-allocated by incremental GC. One unique feature of its API is that it separates opening and closing of tags so that it is suitable as a compilation target for templating languages that allow (temporarily) unbalanced HTML in templates (e.g. tags that are opened and closed in separate templates) and arbitrary logic for creating HTML attributes. Think of it as ASM.dom.
Supported Browsers
Incremental DOM supports IE9 and above.
Usage
HTML is expressed in Incremental DOM using the elementOpen
, elementClose
, elementVoid
and text
methods. Consider the following example:
var IncrementalDOM = require('incremental-dom'),
elementOpen = IncrementalDOM.elementOpen,
elementClose = IncrementalDOM.elementClose,
elementVoid = IncrementalDOM.elementVoid,
text = IncrementalDOM.text;
function render(data) {
elementVoid('input', '', [ 'type', 'text' ]);
elementOpen('div', '', null);
if (data.someCondition) {
text(data.text);
}
elementClose('div');
}
To render or update an existing DOM node, the patch function is used:
var patch = require('incremental-dom').patch;
var data = {
text: 'Hello World!',
someCondition: true
};
patch(myElement, function() {
render(data);
});
data.text = 'Hello World!';
patch(myElement, function() {
render(data);
});
Templating Languages and Libraries
Check out what others having been doing with Incremental DOM.
Docs
Getting Incremental DOM
Via CDN
https://ajax.googleapis.com/ajax/libs/incrementaldom/0.5.1/incremental-dom.js https://ajax.googleapis.com/ajax/libs/incrementaldom/0.5.1/incremental-dom-min.js
Using npm
npm install incremental-dom
Development
To install the required development packages, run the following command:
npm i
Running tests
To run once:
./node_modules/.bin/bazelisk test ...
To run on change:
./node_modules/.bin/ibazel run //test:unit_tests
Building
To build once:
./node_modules/.bin/bazelisk build ...
To build on change:
./node_modules/.bin/ibazel build ...
Top Related Projects
The library for web and native user interfaces.
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
Deliver web apps with confidence 🚀
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
Cybernetically enhanced web apps
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot