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.
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!
var vdom = var hyperx = var hx = var title = 'world'var wow = 123var tree = hx`<div> <h1 y="abcd">hello !</h1> wow </div>`consoleoutput:
$ node vdom.js<div> <h1 y="ab3cd">hello world!</h1> <i>cool</i> wow <b>1</b><b>2</b><b>3</b></div>var React = var toString = renderToStringvar hyperx = var hx = var title = 'world'var wow = 123var tree = hx`<div> <h1 y="abcd">hello !</h1> wow </div>`consolevar h = var hyperx = var hx = var title = 'world'var wow = 123var tree = hx`<div> <h1 y="abcd">hello !</h1> wow </div>`consolevar vdom = var hyperx = var hx = var main = var loop = document { return hx`<div> <h1>clicked times</h1> <button onclick=>click me!</button> </div>` { loop }}var React = var render = rendervar hyperx = var hx = var App = Reactvar hyperx = var convertTaggedTemplateOutputToDomBuilder = convertTaggedTemplateOutputToDomBuilder`<h1>hello world</h1>` // Running this produces: h1 {} [ 'hello world' ] var hyperx = require('hyperx')Return a tagged template function hx from a hyperscript-style factory function
h.
Values to use for h:
vdom.hReact.createElementOptionally 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.BSD
npm install hyperx