Giter Club home page Giter Club logo

dom-expressions's Introduction

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;

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 };

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.

dom-expressions's People

Contributors

amoutonbrady avatar atk avatar cynecx avatar dependabot[bot] avatar edemaine avatar elite174 avatar fernandolguevara avatar fictitious avatar frenzzy avatar hugojosefson avatar lxsmnsyc avatar mduclehcm avatar mdynnl avatar nicketson avatar novacrazy avatar obask avatar paulshen avatar pavulon avatar peterlitszo avatar ricochet1k avatar ryansolid avatar shadowtime2000 avatar trusktr avatar ulivz avatar vjoao avatar xstevenyung avatar yuens1002 avatar yw662 avatar zearin avatar zoy-l avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.