npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dom2idom

v0.3.3

Published

DOM fragment or HTML string to IncrementalDOM instructions runtime interpreter

Downloads

6

Readme

In place DOM to DOM mutations, via Incremental DOM.

DISCLAIMER

This came out of curiosity, it's a very inefficient way to use Incremental DOM, and should absolutely not be your pick for new projects.

In old existing codebases that you need to put your hands on, it may help you take advantage of in place mutations and refactor things in a bit more declarative style without modifing your UI DOM generation. For such codebases it comes as a relatively lightweight dependecy (IncrementalDOM is < 10Kb).

Live demos

circles, benchmark to get a measure of inefficiency

Usage
// Make yourself an helper
function patch(target, frag) {
  IncrementalDOM.patch(target, dom2idom, frag)
}

// If you live in JQuery chains
$.fn.patch = function (target) {
  IncrementalDOM.patch(target.get(0), dom2idom, this.get(0))
  return this
}

// If you like the danger or are convinced this should be part of the standard
Element.prototype.patch = function (frag) {
  IncrementalDOM.patch(this, dom2idom, frag)
}
How does it work?

It will take an HTML string, a DOM fragment, or an equivalent plain object, and execute its equivalent Incremental DOM instructions.

In the circles demo you can clearly see the difference between replacing the innerHTML and patching it, from the devtools Elements tab.

Mutating the DOM in place means its current elements instances will be respected, this is of great advantage when updating your UI.

Although not of great help with static content, you can optionally assign elements a key or declare that their descendants should be skipped by assigning attributes to you static DOM fragment <div key="unique" skip="true">, you can change the attrs name in the code. For more on keys and skip usage refere to the Incremental DOM documentation.

DOM equivalent plain object?

An object with the exact same properties as the DOM interface, thus parsable just as real DOM. This gives you serialized cachable DOM without string parsers. You can find two little gists here:

dom2domobj, from DOM fragment or HTML string.

jsonml2domobj, from JSOML.