
Product
Socket Now Protects the Chrome Extension Ecosystem
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Actualize is a very efficient and fast DOM patching algorithm. It's inspired by morphdom and nanomorph. It works with a real DOM, so a virtual DOM is not required.
npm install actualize
ES2015
import actualize from 'actualize'
CommonJS
const actualize = require('actualize')
Browser
<script src="https://unpkg.com/actualize@latest/dist/actualize.js"></script>
It injects actualize
global into your environment.
import actualize from 'actualize'
const nodeA = document.createElement('button')
nodeA.textContent = 'Open'
const nodeB = document.createElement('button')
nodeB.className = 'pressed'
nodeB.textContent = 'Close'
nodeA.outerHTML === '<button>Open</button>' // true
actualize(nodeA, nodeB)
nodeA.outerHTML === '<button class="pressed">Close</button>' // true
Actualize can be used in combination with domb,
a convenient tool for generating DOM trees.
The above example can be rewriten using domb
as follows:
import actualize from 'actualize'
import { button } from 'domb'
const nodeA = button({ children : 'Open '})
const nodeB = button({ children : 'Close', className : 'pressed' })
actualize(nodeA, nodeB)
It's common to work with lists of items in the DOM.
Adding, removing or reordering items in a list can be quite expensive.
To optimize this, you can add an id
attribute to the DOM node.
When changing the order of nodes, actualize
will compare nodes with
the same ID with each other, which will lead to a much smaller numbers of re-renders.
The getKey
option can be used to configure the key property for this purpose (see below).
actualize(treeA, treeB, options)
The actualize
function supports the following arguments:
treeA: Node
— node for updatingtreeB: Node
— node to which treeA
should be updatedoptions: object
— see below supported optionsThe return value will usually be treeA
.
However, in situations where treeA
is incompatible with treeB
(either a different node type or a different tag name) then treeB
will be returned.
Supported options (all optional):
Option: type | Description |
---|---|
childrenOnly: boolean | Update only the child nodes of the treeA , the element itself will be skipped. The default value is false . |
getKey: function(node) | Called to get a custom key of the node in a child list. The default value is node.id . |
nodeWillMount: function(nodeB) | Called before a node from the B tree is mounted to the A tree. |
nodeDidMount: function(nodeB) | Called after a node from the B tree has been mounted to the A tree. |
nodeWillUnmount: function(nodeA) | Called before a node in the A tree is unmounted. |
nodeDidUnmount: function(nodeA) | Called after a node in the A tree has been unmounted. |
nodeWillUpdate: function(nodeA, nodeB) | Called before updating a node in the A tree. |
nodeDidUpdate: function(nodeA, nodeB) | Called after updating a node in the A tree. |
childrenWillUpdate: function(nodeA, nodeB) | Called before updating the child nodes of an element in the A tree. |
childrenDidUpdate: function(nodeA, nodeB) | Called after updating the child nodes of an element in the A tree. |
⚠️ actualize
will modify the treeB
and it should be discarded after use.
FAQs
DOM patching algorithm
The npm package actualize receives a total of 40 weekly downloads. As such, actualize popularity was classified as not popular.
We found that actualize demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.