loilo-archive / domify-template-strings Goto Github PK
View Code? Open in Web Editor NEWInterpolate DOM Nodes into ES2015 Template Strings
Interpolate DOM Nodes into ES2015 Template Strings
Handling fragments is simpler, because it works with native methods:
document.body.appendChild(Inst.list('<p></p><p></p>'))
Template strings are cool, so cool.
However they cannot be instantiated from string without eval, so it's somehow not natural for regular front-end programmers to use return new Function(...)
syntax to load some template string from current document, to be merged using domify later.
Maybe domify could expose a .eval
method that would construct such a Function ?
domify.eval(htmlStr) -> function callmetomerge(A, B, ...) {} -> returns merged DOM
where htmlStr contains ${A}
, ${B}
, and so on...
I'm thinking about a feature allowing the following:
function greet () {
alert('Hello!')
}
domify `<button onclick=${greet}>Greet</button>`
Or even shorter:
domify `<button onclick=${() => alert("Hello!")}>Greet</button>`
That should not be too hard to implement.
Because
template tags allow any HTML (even elements out of context)
@see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template
https://github.com/straker/html-tagged-template/blob/c06f23ac/index.js#L150-L157
Returning an array of <option>
nodes inside a select won't work because the placeholders are discarded as invalid inside <select>
.
Note that https://github.com/GinjiBan/jsdom-global is a PR for using jsdom 10 within jsdom-global.
I might PR that request.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.