Giter Site home page Giter Site logo

picodom's Introduction

Travis CI Codecov npm

Picodom is a 1 KB Virtual DOM builder and patch function.

Try it Online

import { h, patch } from "picodom"

let element, oldNode

function render(node) {
  return element = patch(oldNode, (oldNode = node), element)
}

function view(state) {
  return (
    <div>
      <h1>{state}</h1>
      <input
        autofocus
        type="text"
        value={state}
        oninput={e => render(view(e.target.value))}
      />
    </div>
  )
}

render(view("Hello!"))

Picodom supports keyed updates & lifecycle events โ€” all with no dependencies. Mix it with your favorite state management library and roll your own custom view framework.

Installation

Download the minified library from a CDN.

<script src="https://unpkg.com/picodom"></script>

Then access the exported global.

const { h, patch } = picodom

Or install with npm / Yarn.

npm i picodom

Then build with a bundler, e.g., Browserify, Rollup, Webpack, etc., and import it.

import { h, patch } from "picodom"

API

h

h(
  string | VirtualComponent,
  Attributes,
  Array<VirtualNode> | string
): VirtualNode

VirtualNode

{
  tag: string,
  data: Attributes,
  children: Array<VirtualNode>
}

VirtualComponent

(any, Array<VirtualNode> | string): VirtualNode

Attributes

HTMLAttributes | SVGAttributes | DOMEvents | VirtualDOMEvents

VirtualDOMEvents

oncreate

Fired after the element is created and attached to the DOM.

oncreate(Element): void

onupdate

Fired after the element attributes are updated. This event will fire even if the attributes have not changed.

onupdate(Element, oldData: Attributes): void

onremove

Fired before the element is removed from the DOM.

onremove(Element): void

patch

patch(
  oldNode: VirtualNode,
  newNode: VirtualNode,
  element: HTMLElement,
  root: HTMLElement | document.body
): HTMLElement

Links

License

Picodom is MIT licensed. See LICENSE.

picodom's People

Contributors

2hu12 avatar andrewiggins avatar jojibucaran avatar pspeter3 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.