All Projects → lukejacksonn → Ijk

lukejacksonn / Ijk

Licence: mit
Transforms arrays into virtual dom trees; a terse alternative to JSX and h

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Ijk

Hyperawesome
A curated list of awesome projects built with Hyperapp & more.
Stars: ✭ 446 (-1.33%)
Mutual labels:  vdom, hyperapp, dom
Val
VirtualDOM abstraction layer - give yourself better integration and full control over the DOM with any virtual DOM library that uses a Hyperscript-like API such as React and Preact.
Stars: ✭ 181 (-59.96%)
Mutual labels:  vdom, dom, preact
Preact
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
Stars: ✭ 30,527 (+6653.76%)
Mutual labels:  vdom, dom, preact
Preact Habitat
Zero configuration Preact widgets renderer in any host DOM
Stars: ✭ 444 (-1.77%)
Mutual labels:  vdom, preact
Vhtml
Render JSX/Hyperscript to HTML strings, without VDOM 🌈
Stars: ✭ 556 (+23.01%)
Mutual labels:  vdom, preact
Nerv
A blazing fast React alternative, compatible with IE8 and React 16.
Stars: ✭ 5,409 (+1096.68%)
Mutual labels:  vdom, preact
Sauron
Sauron is an html web framework for building web-apps. It is heavily inspired by elm.
Stars: ✭ 1,217 (+169.25%)
Mutual labels:  vdom, dom
Marko
A declarative, HTML-based language that makes building web apps fun
Stars: ✭ 10,796 (+2288.5%)
Mutual labels:  vdom, dom
Superfine
Absolutely minimal view layer for building web interfaces.
Stars: ✭ 1,542 (+241.15%)
Mutual labels:  vdom, hyperapp
Preact Render Spy
Render preact components with access to the produced virtual dom for testing.
Stars: ✭ 178 (-60.62%)
Mutual labels:  vdom, preact
Asm Dom
A minimal WebAssembly virtual DOM to build C++ SPA (Single page applications)
Stars: ✭ 2,604 (+476.11%)
Mutual labels:  vdom, dom
Hydux
A light-weight type-safe Elm-like alternative for Redux ecosystem, inspired by hyperapp and Elmish
Stars: ✭ 216 (-52.21%)
Mutual labels:  hyperapp, preact
Scoped Style
A tiny css in js library 🚀
Stars: ✭ 129 (-71.46%)
Mutual labels:  hyperapp, preact
bassdrum
reactive, type safe components with preact and rxjs.
Stars: ✭ 44 (-90.27%)
Mutual labels:  preact, dom
Preact Worker Demo
Demo of preact rendering an entire app in a Web Worker.
Stars: ✭ 204 (-54.87%)
Mutual labels:  dom, preact
Preact Markup
⚡️ Render HTML5 as VDOM, with Components as Custom Elements!
Stars: ✭ 167 (-63.05%)
Mutual labels:  dom, preact
Goober
🥜 goober, a less than 1KB 🎉 css-in-js alternative with a familiar API
Stars: ✭ 2,317 (+412.61%)
Mutual labels:  dom, preact
Preact Portal
📡 Render Preact components in (a) SPACE 🌌 🌠
Stars: ✭ 160 (-64.6%)
Mutual labels:  dom, preact
Omi
Front End Cross-Frameworks Framework - 前端跨框架跨平台框架
Stars: ✭ 12,153 (+2588.72%)
Mutual labels:  vdom, preact
hyperapp-example
hyperapp example
Stars: ✭ 14 (-96.9%)
Mutual labels:  preact, hyperapp

ijk

Transforms arrays into virtual DOM trees

Build Status codecov

Find h a bit repetitive? Not a huge fan of JSX? Love LISP? Code as data and data as code?

This is a tiny recursive factory function that allows you to write terse, declarative representations of virtual DOM trees. It does not try mimic HTML or JSON syntax but instead a series of nested arrays to represent user interfaces.

const tree = h('x', 'y', 'z')
(
  ['main', [
    ['h1', 'Hello World'],
    ['input', { type: 'range' }],
    ['button', { onclick: console.log }, 'Log Event'],
  ]]
)

The above call to h returns a virtual DOM tree with named attributes that respect the provided schema. Expected output here, would be of the shape { x: 'main', y: {}, z: [...] }. A tree like this can be passed as a node to patch, diff and render algorithms exposed by libraries like Hyperapp, Ultradom or Preact.

Schemas

  • Hyperapp / Ultradom / Preact: h('nodeName','attributes','children')

Signature

A call to h(x,y,z) returns a build function that expects a node of type [0,1,2] where:

  • Index 0 contains a string used as the elements tag name (required)
  • Index 1 contains an object containing element attributes (optional)
  • Index 2 contains an string|array of content or children (optional)

Children are flattened and falsey children are excluded. Numbers passed as children get converted to strings.

Installation

npm i ijk

Usage

Here is a demo with Hyperapp and Preact.

import { h } from 'ijk'

const tree = h('nodeName', 'attributes', 'children')(
  ['main', [
    ['h1', 'Hello World'],
    ['input', { type: 'range' }],
    ['button', { onclick: console.log }, 'Log Event'],
    ['ul', [
      ['li', 1],
      ['li', 2],
      ['li', 3]
    ]],
    false && ['span', 'Hidden']
  ]]
)

Comparison

ijk is essentially h but with optional props and you only have to call h once; not every time you want to represent an element in the DOM. This generally means less repetition and one less import in your view files.

const h =
  h('main', {}, [
    h('h1', {}, 'Hello World'),
    h('input', { type: 'range' }),
    h('button', { onclick: console.log }, 'Log Event'),
    h('ul', {}, [
      h('li', {}, 1),
      h('li', {}, 2),
      h('li', {}, 3),
    ]),
    false && h('span', {}, 'Hidden')
  ])

The main advantages over using JSX is less repetition of tag names and no build step is required.

const jsx =
  <main>
    <h1>Hello World</h1>
    <input type='range' />
    <button onclick={ console.log }>Log Event</button>
    <ul>
      <li>1</li>
      <li>2</li>
      <li>3</li>
    </ul>
    {false && <span>'Hidden'</span>}
  </main>

Advanced

Here is an example that takes advantage of most features and demonstrates components.

import { h } from 'ijk'

const Item = data => ['li', data]
const Article = ({ title, story, related }) => [
  'article',
  [
    ['h2', title],
    ['hr'],
    ['p', story],
    related.map(Item),
  ]
]

const Main =
  ['main', [
    ['h1', 'Hello World'],
    ['input', { type: 'range' }],
    ['ul', [
      ['li', 1],
      ['li', 2],
      ['li', 3],
    ]],
    ['button', { onclick: console.log }, 'Log Event'],
    false && ['span', 'Hidden'],
    Article({
      title: 'Some News',
      story: 'lorem ipsum dolor sit amet',
      related: [4,5],
    })
  ]]

const tree = h('nodeName', 'attributes', 'children')(Main)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].