HyperX
is a module that translates a tagged template literal to a hyperscript
function like the one included with virtual-dom
.
Snabbdom
uses a hyperscript-like function to build it's vdoms, but it's second argument is different. Instead of attributes it's properties are used by various "modules";
h('div', {
props: {title: someString}, // snabbdom/modules/props
classes: {selected: isSelected}, // snabbdom/modules/class
on: {click: doSomething}, // snabbdom/modules/eventlisteners
style: {color: someColor} // snabbdom/modules/style
}, ['children']);
Is it possible to use hyperx
with snabbdom
's hyperscript function like so:
const h = require('snabbdom/h');
const hyperx = require('hyperx');
const hx = hyperx(h);
let vdom = hx`
<div
title=${someString}
class-selected={isSelected}
on-click={doSomething}
style={({color: someColor})}
>
children
</div>
`;
Yes you can!
check the working code here