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

dom-expressions

v0.37.20

Published

A Fine-Grained Runtime for Performant DOM Rendering

Downloads

844

Readme

DOM Expressions

Build Status Coverage Status NPM Version Gitter

DOM Expressions is a Rendering Runtime for reactive libraries that do fine grained change detection. These libraries rely on concepts like Observables and Signals rather than Lifecycle functions and the Virtual DOM. Standard JSX transformers are not helpful to these libraries as they need to evaluate their expressions in isolation to avoid re-rendering unnecessary parts of the DOM.

This package wraps libraries like KnockoutJS or MobX and use them independent of their current render systems using a small library to render pure DOM expressions. This approach has been proven to be incredibly fast, dominating the highest rankings in the JS Framework Benchmark.

It is designed to be used with a companion render API. Currently there is a JSX Babel Plugin, and Tagged Template Literals, and HyperScript runtime APIs. Most developers will not use this package directly. It is intended to help author your own Reactive Libraries and not to be used directly in projects.

Example Implementations

  • Solid: A declarative JavaScript library for building user interfaces.
  • mobx-jsx: Ever wondered how much more performant MobX is without React? A lot.
  • vuerx-jsx: Ever wondered how much more performant Vue is without Vue? ...renderer built on @vue/reactivity
  • ko-jsx: Knockout JS with JSX rendering.
  • s-jsx: Testbed for trying new techniques in the fine grained space.

Runtime Generator

Dom Expressions is designed to allow you to create a runtime to be tree shakeable. It does that by using "babel-plugin-transform-rename-import" to rename the import to your reactive core file. Setup the babel plugin and then export * from "dom-expressions/src/runtime"from your runtime. Be sure to not exclude the dom-expressions node_module.

{
  plugins: [
    [
      "babel-plugin-transform-rename-import",
      {
        original: "rxcore",
        replacement: "../src/core"
      }
    ]
  ];
}

What is the reactive core file. It exports an object with the methods required by the runtime. Example:

import S, { root, value, sample } from "s-js";

const currentContext = null;
const sharedConfig = {};

function memo(fn, equal) {
  if (typeof fn !== "function") return fn;
  if (!equal) return S(fn);
  const s = value(sample(fn));
  S(() => s(fn()));
  return s;
}

function createComponent(Comp, props) {
  return sample(() => Comp(props));
}

export { root, S as effect, memo, createComponent, currentContext, sharedConfig };

Runtime Renderers

Once you have generated a runtime it can be used with companion render APIs:

JSX

Babel Plugin JSX DOM Expressions is by far the best way to use this library. Pre-compilation lends to the best performance since the whole template can be analyzed and optimal compiled into the most performant JavaScript. This allows for not only the most performant code, but the cleanest and the smallest.

Tagged Template

If precompilation is not an option Tagged Template Literals are the next best thing. Lit DOM Expressions provides a similar experience to the JSX, compiling templates at runtime into similar code on first run. This option is the largest in size and memory usage but it keeps most of the performance and syntax from the JSX version.

HyperScript

While not as performant as the other options this library provides a mechanism to expose a HyperScript version. Hyper DOM Expressions offers the greatest flexibility working with existing tooling for HyperScript and enables pure JS DSLs.

Work in Progress

This is still a work in progress. My goal here is to better understand and generalize this approach to provide non Virtual DOM alternatives to developing web applications.