Giter VIP home page Giter VIP logo

js-imm-dom's Introduction

Immediate-Mode DOM Tools

Lightweight tooling around DOM creation. Designed to be embedded piecewise in self-contained Web Components.

I love virtual DOM libraries like superfine, preact, and inferno. But not all creations need the efficient updating logic. Creations like self-sufficient Web Components, where every byte of superfluous logic is wasted.

The imm-dom library enables concise expression of DOM creation, while never setting innerHTML with uncontrolled content. Elements are created using createElement() or createElementNS(). Strings become Text nodes via createTextNode() or elem.append(). Attributes are set using elem.setAttribute(). DOM injection is protected against, in conjunction with caution and expertise, to provide tools for dynamic content.

Demo

See the mini demo and the demo's index.html source.

API

imm-dom provdes layers of DOM tools:

  • Creating new DOM elements, both HTML and SVG
  • Manipulating (existing) DOM elements
  • Defining Web Components
  • Misc utilities: promises, deferreds, render animation frames, etc.

Read more in docs/README.md

<section>
  <imm-demo-cdn data-demo=yes kind=awesome title='my demo title'>
    some body text for the CDN demo
  </imm-demo-cdn>

  <script type=module>
    import {imm_html as h, ImmElem} from 'https://cdn.jsdelivr.net/npm/imm-dom@latest/esm/index.mjs'

    ImmElem.elem('imm-demo-cdn', ns =>
      h.article(
        {class: ns.kind},
        h.h3(`${ns.title}`),
        h.slot('Body text Slot')) )
  </script>
</section>

Inspired by:

imm_html.article({class: 'awesome'},
  imm_html.h3('my demo title'),
  'some body text')

// or

tag('article', {class: 'awesome'},
  tag('h3', 'my demo title'),
  'some body text')

Inspired by:

imm_tmpl`
  <article ${ {class: 'awesome'} }>
    <h3>${ 'my demo title' }</h3>
    ${ 'some body text' }
  </article>`

Inspired by:

  • imm_raf() returns a promise for the next requestAnimationFrame tick.
  • ImmRAF is like ImmElem using requestAnimationFrame to decouple attribute updates from rendering.

Size Cost in Bytes

To be embedded in each web component custom element, the individual pieces must be small.

The entire library is ~ 7800 bytes minified; ~ 3100 brotli. However, the library is designed to include only the parts actually used. Perfect for pairing with a tree-shaking tool like rollup.

module brotli minified source
index 3058 B 7768 B 15762 B
imm_elem 1026 B 2471 B 4877 B
imm_tmpl 870 B 1834 B 4849 B
imm_dom 570 B 1164 B 2474 B

See auto-generated compressed size report.

License

BSD 2-clause

js-imm-dom's People

Contributors

rb-brandon avatar shanewholloway 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.