Tiny DOM library
npm install redom
import { el, mount, text } from 'redom';
const h1 = el('h1');
const hello = h1(text('Hello world!'));
mount(document.body, hello);
var redom = require('redom');
var el = redom.el;
var mount = redom.mount;
var text = redom.text;
<script src="https://redom.js.org/redom.min.js"></script>
var el = redom.el;
var mount = redom.mount;
var text = redom.text;
import { el, text, mount } from 'redom';
import { children, props, events } from 'redom';
// Define element tags
const form = el('form');
const input = el('input');
const button = el('button');
// Define component
const login = form(
children(el => [
el.email = input(props({ type: 'email' })),
el.pass = input(props({ type: 'pass' })),
el.submit = button(text('Sign in'))
]),
events({
onsubmit (el, e) {
e.preventDefault();
console.log(el.email.value, el.pass.value);
}
})
);
// Mount to DOM
mount(document.body, login);
import { el, list, mount, update } from 'redom';
// Define element tags
const table = el('table');
const tbody = el('tbody');
const tr = el('tr');
const td = el('td');
// Define components
const cell = (data) => td(
update((el, data) => {
el.textContent = data;
})
)
const row = (data) => tr(
children(el => [
el.cols = list(el, cell)
]),
update((el, data) => {
el.cols.update(data)
})
);
// Init the app
const app = table(
children(el => [
el.rows = list(tbody(), row)
]),
update((el, data) => {
el.rows.update(data.tbody)
})
)
// Mount to DOM
mount(document.body, app);
// update app
app.update({
tbody: [
[ 1, 2, 3 ]
]
});
Documentation is a bit lacking yet, please check out the source for now: https://github.com/pakastin/redom/tree/master/src
Special thanks to maciejhirsz for the bind trick!