package
tagged template string virtual dom builder
npm install hyperxGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 2 packages.
47.0 kB
Includes dependencies.
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 = 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
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>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 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>${
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>`
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>
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' ]var hyperx = require('hyperx')Return a tagged template function hx from a hyperscript-style factory function
h.
Values to use for h:
vdom.hReact.createElement with parameter children spreadOptionally 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 falseopts.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 literalBSD
npm install hyperxbenlyn
bendik.lynghaug@gmail.com
bret
bcomnes@gmail.com
lrlna
shestak.irina@gmail.com
yerkopalma
yerko.palma@usach.cl
juliangruber
julian@juliangruber.com
timwis
tim@timwis.com
ahdinosaur
michael.williams@enspiral.com
toddself
todd@selfassembled.org
sethvincent
sethvincent@gmail.com
maxogden
max@maxogden.com
shama
kyle@dontkry.com
freeman-lab
jeremy.freeman@mac.com
feross
feross@feross.org
emilbayes
github@tixz.dk
colingourlay
colin@colin-gourlay.com
jameskyburz
james.kyburz@gmail.com
almost
tom@almostobsolete.net
slaskis
robert@publicclass.se
ungoldman
ungoldman@gmail.com
graforlock
neatcube@gmail.com
tornqvist
carl@tornqv.ist
amongiants
jon@folderstudio.com
goto-bus-stop
npm@asdf.kooi.me
mafintosh
mathiasbuus@gmail.com