xml-light
Simple functions to generate XML/HTML in JavaScript.
Super compact package at less than 40 lines of code.
Virtual Hypertext
Use the Virtual Hypertext _
method.
_(tag: string, attributes: {}, ...children: string[]): string;
Example:
var xml = ;var _ = xml_; var html = ;console;//<div class="wrapper"><div class="avatar"><img src="..."/><span>Hello there</span><br/></div></div>
POJO
Create XML from a plain JavaScript Array object, where first element is the name of XML tag, the second is an object of attributes and the rest of the elements of the array are its children nodes.
type VNode = [tag: string, attributes: {}, ...children: VNode[]];
xml(root: VNode, h = _);
Example:
var xml = xml; var pojo = 'div' 'class': 'wrapper' 'div' 'class': 'avatar' 'img' src: '...' 'span' null 'Hello there' 'br' ;console;// <div class="wrapper"><div class="avatar"><img src="..."/><span>Hello there</span><br/></div></div>
React
The second argument to the xml
function is a virtual hypertext generator function, you can provide
React.createElement.bind(React)
to it to generate React virtual DOM.
Generate React Virtual DOM representations from POJO lists instead of using React.createElement
or .jsx
files and compiling them to .js
.
var xml = xml;var react_dom = ;
This is equivalent to:
var react_dom = React;
You might consider creating a React Virtual Hypertext method for convenience:
Reacth = ReactcreateElement; var react_dom = ;
Or even:
React { return ;};
So now, instead installing .jsx
to .js
compiler and writing your components in some weird xml-js
mix language:
var CommentBox = React;
You can do everything in 100% JavaScript:
var CommentBox = React;
TypeScript definitions for your extension:
declare