I've tried to roll out my own HyperScript implementation. I would be interested in any suggestions to improve it or point me to any other better implementation which is still maintained. I checked the HyperScript project, but it doesn't seem to have any recent updates, so I tried this:
var DOM = {
h: function(tagName, props, children) {
var element = document.createElement(tagName);
if (props) {
for (var item in props) {
element[item] = props[item];
}
}
if (children && Array.isArray(children) && children.length > 0) {
children.forEach(function(child) {
element.appendChild(child);
});
}
return element;
},
div: function(props, children) {
return this.h('div', props, children);
},
label: function(props, children) {
return this.h('label', props, children);
},
input: function(props, children) {
return this.h('input', props, children);
},
button: function(props, children) {
return this.h('button', props, children);
},
li: function(props, children) {
return this.h('li', props, children);
}
};
Usage:
DOM.button({ className: "destroy" });