hyperxify

2.0.1 • Public • Published

hyperxify

browserify transform for hyperx

This module will compile your hyperx template strings down to javascript expressions so that you don't need to send the hyperx library over the wire.

example

Given some hyperx code:

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 })
  }
}

Compile with browserify using -t hyperxify:

$ browserify -t hyperxify main.js > bundle.js

If you look in the bundle.js file, you can see that the hyperx template strings have been replaced with calls to vdom.h, which is how hyperx was invoked:

$ <bundle.js head -n16 | tail -n+2
var vdom = require('virtual-dom')
var hyperx = 0
var hx = 0

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

function render (state) {
  return vdom.h("div",{},["\n    ",vdom.h("h1",{},["clicked ",state.times," times"]),"\n    ",vdom.h("button",{"onclick":onclick},["click me!"]),"\n  "])

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

license

BSD

Package Sidebar

Install

npm i hyperxify

Weekly Downloads

3

Version

2.0.1

License

BSD

Last publish

Collaborators

  • mreinstein
  • benlyn
  • s3ththompson
  • yoshuawuyts
  • bret
  • lrlna
  • yerkopalma
  • juliangruber
  • timwis
  • ahdinosaur
  • toddself
  • sethvincent
  • maxogden
  • shama
  • freeman-lab
  • feross
  • emilbayes
  • colingourlay
  • jameskyburz
  • almost
  • slaskis
  • ungoldman
  • graforlock
  • tornqvist
  • amongiants
  • goto-bus-stop
  • mafintosh