1.0.5 • Published 3 years ago

@transclusion/vdom v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@transclusion/vdom

A tiny JavaScript virtual DOM library for the browser and Node.js.

npm install @transclusion/vdom --save

build status coverage status npm version

Features

  • Serializable diffs. Allows splitting application logic between the main thread and a worker thread.
  • Modular. Use only what you need. Provides building blocks for your own opinionated view library.
  • Pure. Handle side-effects in handler functions, not in the application logic.
  • Fast. Blazing fast rendering times.
  • Light. Weighs in at 2.5 KB minified+gzipped.
  • Use JSX. Comes with a JSX-compatible pragma function out of the box which works with Babel and TypeScript.
  • Typed. Written in TypeScript.

Documentation

See API documentation.

Usage

A basic counter example:

/** @jsx createVElement */

import {createVElement, diff, patch, toVNode} from '@transclusion/vdom'

// Define `counter` component

const counter = {
  // Returns the initial model
  init() {
    return 0
  },

  // Updates the model
  update(model, msg) {
    switch (msg) {
      case 'DECR':
        return model - 1
      case 'INCR':
        return model + 1
      default:
        return model
    }
  },

  // Renders the model to a view representation (vdom)
  view(model) {
    return (
      <div id="root">
        <button on={{click: 'DECR'}}>-</button>
        <span>{model}</span>
        <button on={{click: 'INCR'}}>+</button>
      </div>
    )
  }
}

// Initialize client-side application

const rootElm = document.getElementById('root')

const context = {
  element: rootElm,
  vNode: toVNode(rootElm),
  model: counter.init()
}

function handleMsg(msg) {
  context.model = counter.update(context.model, msg)
  render()
}

function render() {
  const nextVNode = counter.view(context.model)
  const patches = diff(context.vNode, nextVNode)

  context.element = patch(context.element, patches, handleMsg)
  context.vNode = nextVNode
}

// Start render cycle
render()

License

MIT © Marius Lundgård

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-beta.5

5 years ago

1.0.0-beta.4

6 years ago

1.0.0-beta.3

6 years ago

1.0.0-beta.2

6 years ago

1.0.0-beta

6 years ago

1.0.0-alpha.5

6 years ago

1.0.0-alpha.4

6 years ago

1.0.0-alpha.3

6 years ago

1.0.0-alpha.2

7 years ago

1.0.0-alpha.1

7 years ago

0.1.3

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago