@tivac/mithril-objectify
v1.0.0-beta.0
Published
Optimize Mithril m() calls into simple JS objects via API, CLI, or Browserify
Downloads
3
Readme
mithril-objectify
Turn mithril html functions like m(".fooga")
into static JS objects like:
{ tag: "div", attrs: { "className" : "fooga" }, children: [ ] }
for speeeeeed.
Use via CLI, API, or as a Browserify transform!
NOTE: This requires iojs
/[email protected]
/[email protected]
to run, it uses ECMAScript 2015 template strings. Sorry!
Installation
Install with npm
npm i mithril-objectify
Usage
CLI
Accepts an input file and optional output file. No output file will echo the result to stdout.
> mithril-objectify ./input.js
> mithril-objectify ./input.js ./output.js
API
Accepts a string or buffer, returns a buffer.
var objectify = require("mithril-objectify");
console.log(objectify(`m(".fooga.wooga.booga")`);
// logs
// ({ tag: "div", attrs: { className: "fooga wooga booga" }, children: [ ] })
Browserify
Use as a browserify transform, either via the CLI or via code.
CLI
browserify -t mithril-objectify <file>
Code
var build = require("browserify")();
build.transform("mithril-objectify");
b.add("./client.js");
b.bundle().pipe(process.stdout);
Warning
There may be edge cases this doesn't handle well. I'd love to see issues filed w/ repro code for any of them and would be happy to fix them!