All Projects β†’ choojs β†’ Hyperx

choojs / Hyperx

Licence: bsd-2-clause
🏷 - tagged template string virtual dom builder

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Hyperx

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 (-81.74%)
Mutual labels:  virtual-dom, dom
Asm Dom
A minimal WebAssembly virtual DOM to build C++ SPA (Single page applications)
Stars: ✭ 2,604 (+162.76%)
Mutual labels:  virtual-dom, dom
Amplesdk
Ample SDK - JavaScript UI Framework
Stars: ✭ 169 (-82.95%)
Mutual labels:  virtual-dom, dom
Squark
Rust frontend framework, for web browser and more.
Stars: ✭ 162 (-83.65%)
Mutual labels:  virtual-dom, dom
respo.cljs
A virtual DOM library built with ClojureScript, inspired by React and Reagent.
Stars: ✭ 232 (-76.59%)
Mutual labels:  virtual-dom, dom
Respo
A virtual DOM library built with ClojureScript, inspired by React and Reagent.
Stars: ✭ 230 (-76.79%)
Mutual labels:  virtual-dom, dom
Preact Worker Demo
Demo of preact rendering an entire app in a Web Worker.
Stars: ✭ 204 (-79.41%)
Mutual labels:  virtual-dom, dom
object-dom
HTML Object Declarative Dom
Stars: ✭ 20 (-97.98%)
Mutual labels:  virtual-dom, dom
Preact
βš›οΈ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
Stars: ✭ 30,527 (+2980.42%)
Mutual labels:  virtual-dom, dom
CalDOM
An agnostic, reactive & minimalist (3kb) JavaScript UI library with direct access to native DOM.
Stars: ✭ 176 (-82.24%)
Mutual labels:  virtual-dom, dom
lego
πŸš€ Web-components made lightweight & Future-Proof.
Stars: ✭ 69 (-93.04%)
Mutual labels:  virtual-dom, dom
Nanomorph
πŸš… - Hyper fast diffing algorithm for real DOM nodes
Stars: ✭ 621 (-37.34%)
Mutual labels:  virtual-dom, dom
Vuejs Credit Score Calculation
A vehicle credit calculation application using VueJS.πŸ‘
Stars: ✭ 12 (-98.79%)
Mutual labels:  virtual-dom
Vent
jQuery inspired DOM events library
Stars: ✭ 30 (-96.97%)
Mutual labels:  dom
Muve
Muve is a micro library for building interactive javascript applications.
Stars: ✭ 11 (-98.89%)
Mutual labels:  virtual-dom
Waff Query
Lightweight DOM manager
Stars: ✭ 9 (-99.09%)
Mutual labels:  dom
Xml
XML without worries
Stars: ✭ 35 (-96.47%)
Mutual labels:  dom
Radi
πŸŒ€Tiny (in size) front-end framework with no extra browser re-flows
Stars: ✭ 946 (-4.54%)
Mutual labels:  dom
Dompurify
DOMPurify - a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. DOMPurify works with a secure default, but offers a lot of configurability and hooks. Demo:
Stars: ✭ 8,177 (+725.13%)
Mutual labels:  dom
Html React Parser
πŸ“ HTML to React parser.
Stars: ✭ 846 (-14.63%)
Mutual labels:  dom

hyperx

tagged template string virtual dom builder

This module is similar to JSX, but provided as a standards-compliant ES6 tagged template string function.

hyperx works with virtual-dom, react, hyperscript, or any DOM builder with a hyperscript-style API: h(tagName, attrs, children).

You might also want to check out the hyperxify browserify transform to statically compile hyperx into javascript expressions to save sending the hyperx parser down the wire.

compatibility

Template strings are available in: node 4+, chrome 41, firefox 34, edge, opera 28, safari 9

If you're targeting these platforms, there's no need to use a transpiler!

examples

virtual-dom node example

var vdom = require('virtual-dom')
var hyperx = require('hyperx')
var hx = hyperx(vdom.h)

var title = 'world'
var wow = [1,2,3]
var tree = hx`<div>
  <h1 y="ab${1+2}cd">hello ${title}!</h1>
  ${hx`<i>cool</i>`}
  wow
  ${wow.map(function (w, i) {
    return hx`<b>${w}</b>\n`
  })}
</div>`
console.log(vdom.create(tree).toString())

output:

$ node vdom.js
<div>
  <h1 y="ab3cd">hello world!</h1>
  <i>cool</i>
  wow
  <b>1</b><b>2</b><b>3</b>
</div>

react node example

var React = require('react')
var toString = require('react-dom/server').renderToString
var hyperx = require('hyperx')
var hx = hyperx(function createElement (component, properties, children) {
  // Pass children as separate arguments to avoid key warnings
  return React.createElement.apply(null, [component, properties].concat(children))
}, {
  createFragment: function createFragment (children) {
    return React.createElement.apply(null, [React.Fragment, {}].concat(children))
  }
})

var title = 'world'
var wow = [1,2,3]
var frag = hx`
  <tr> <td>row1</td> </tr>
  <tr> <td>row2</td> </tr>
`
var tree = hx`<div>
  <h1 y="ab${1+2}cd">hello ${title}!</h1>
  ${hx`<i>cool</i>`}
  wow
  ${wow.map(function (w, i) {
    return hx`<b>${w}</b>\n`
  })}

  <table>${frag}</table>
</div>`
console.log(toString(tree))

hyperscript node example

var h = require('hyperscript')
var hyperx = require('hyperx')
var hx = hyperx(h)

var title = 'world'
var wow = [1,2,3]
var tree = hx`<div>
  <h1 data-y="ab${1+2}cd">hello ${title}!</h1>
  ${hx`<i>cool</i>`}
  wow
  ${wow.map(function (w) {
    return hx`<b>${w}</b>\n`
  })}
</div>`
console.log(tree.outerHTML)

virtual-dom/main-loop browser example

var vdom = require('virtual-dom')
var hyperx = require('hyperx')
var hx = hyperx(vdom.h)

var main = require('main-loop')
var loop = main({ times: 0 }, render, vdom)
document.querySelector('#content').appendChild(loop.target)

function render (state) {
  return hx`<div>
    <h1>clicked ${state.times} times</h1>
    <button onclick=${onclick}>click me!</button>
  </div>`

  function onclick () {
    loop.update({ times: state.times + 1 })
  }
}

react browser example

var React = require('react')
var render = require('react-dom').render
var hyperx = require('hyperx')
var hx = hyperx(React.createElement)

var App = React.createClass({
  getInitialState: function () { return { n: 0 } },
  render: function () {
    return hx`<div>
      <h1>clicked ${this.state.n} times</h1>
      <button onClick=${this.handleClick}>click me!</button>
    </div>`
  },
  handleClick: function () {
    this.setState({ n: this.state.n + 1 })
  }
})
render(React.createElement(App), document.querySelector('#content'))

console.log example

var hyperx = require('hyperx')

var convertTaggedTemplateOutputToDomBuilder = hyperx(function (tagName, attrs, children) {
  console.log(tagName, attrs, children)
})

convertTaggedTemplateOutputToDomBuilder`<h1>hello world</h1>`

// Running this produces: h1 {} [ 'hello world' ]

api

var hyperx = require('hyperx')

var hx = hyperx(h, opts={})

Return a tagged template function hx from a hyperscript-style factory function h.

Values to use for h:

  • virtual-dom - vdom.h
  • react - React.createElement with parameter children spread
  • hyperscript - hyperscript

Optionally provide:

  • opts.concat(a, b) - custom concatenation function to combine quasiliteral strings with expressions. The h factory function will receive the objects returned by the concatenation function and can make specific use of them. This is useful if you want to implement a pre-processor to generate javascript from hyperx syntax.
  • opts.attrToProp - turn off attribute to property conversions when false
  • opts.createFragment - if your template string has multiple root elements, they will be provided as an array to this function. the return value will then be returned by the template literal

prior art

license

BSD

install

npm install hyperx
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].