support mithril Optimizing Performance
Opened this issue · 4 comments
The macro takes regular Mithril templates like the one below:
var view = function() {
return m("a", {href: "http://google.com"}, "test");
}
It pre-processes the m() call and replaces it with its output:
var view = function() {
return {tag: "a", attrs: {href: "http://google.com"}, children: "test"};
}
Yeah I guess we would need to modify template-compiler.sjs, to be able to read both mithril and sugar tags - it isn't really part of mithril, but rather a external functionality, perhaps you should raise it against the project here:
https://github.com/lhorie/mithril/blob/master/tools/template-compiler.sjs
Alternatively, I'd imagine a simple way to make this work would be to add a pre-processing step that turns the element function calls into mithril code again, eg:
DIV(...)
becomes:
m("DIV", ...)
I'd be happy to include a version of template-compiler.sjs with the sugartags project that supports both, if you are able to make the modifications, and do a PR.
Prepending a compilation step seems the way to go for this.
But it seems a bit like reimplementing the wheel for nothing. Perhaps a sweet.js macro version of Sugartags is simpler?
[edit: sorry for the hasty post, i shouldve payed a bit more attention. i see that optimizer is already using sweet.js; all is awesome then. we just need the new macros, be it in a separate sjs file to be added as a separate grunt step, or appended to the current sjs file]