RE:DOM – Tiny DOM library
redom.js.org
RE:DOM – Tiny DOM library
1–10 of 84 posts
Re: RE:DOM – Tiny DOM library
#2Re: RE:DOM – Tiny DOM library
#3 children(el => [
el.email = input(props({ type: 'email' })),
el.pass = input(props({ type: 'pass' })),
el.submit = button(text('Sign in'))
])
Can someone explains what this does and why it is used here?
As i understand it this function both modifies the `el` object (whatever that is) and returns an array containing the input elements, but why would you want to do both those things at the same time?Re: RE:DOM – Tiny DOM library
#4I've never seen this before: children(el => [ el.email = input(props({ type: 'email' })), el.pass = input(props({ type: 'pass' })), el.submit = button(text('Sign in')) ]) Can someone explains what this does and why it is used here? As i understand it this function both modifies the `el` object (whatever that is) and returns an array containing the input elements, but why would you want to do both those things at the…
> find('elements').clear('contents').add('border')
Re: RE:DOM – Tiny DOM library
#5I've never seen this before: children(el => [ el.email = input(props({ type: 'email' })), el.pass = input(props({ type: 'pass' })), el.submit = button(text('Sign in')) ]) Can someone explains what this does and why it is used here? As i understand it this function both modifies the `el` object (whatever that is) and returns an array containing the input elements, but why would you want to do both those things at the…
children(function(el) {
var a, b, c;
a = input(props({ type: 'email' }));
el.email = a;
// etc
return [a, b, c];
})
Entirely guesswork but:
El is the form element you're defining children on.
You need to provide references to the elements you're creating so that you can use them later (el.email and friends) but you also need to return them to the children function in an ordered manner so that it can actually attach them into the DOM.Re: RE:DOM – Tiny DOM library
#6I've never seen this before: children(el => [ el.email = input(props({ type: 'email' })), el.pass = input(props({ type: 'pass' })), el.submit = button(text('Sign in')) ]) Can someone explains what this does and why it is used here? As i understand it this function both modifies the `el` object (whatever that is) and returns an array containing the input elements, but why would you want to do both those things at the…
I'd assume it's argument chaining, e.g.: > find('elements').clear('contents').add('border')
Re: RE:DOM – Tiny DOM library
#7I've never seen this before: children(el => [ el.email = input(props({ type: 'email' })), el.pass = input(props({ type: 'pass' })), el.submit = button(text('Sign in')) ]) Can someone explains what this does and why it is used here? As i understand it this function both modifies the `el` object (whatever that is) and returns an array containing the input elements, but why would you want to do both those things at the…
children(function(el) { var a, b, c; a = input(props({ type: 'email' })); el.email = a; // etc return [a, b, c]; }) Entirely guesswork but: El is the form element you're defining children on. You need to provide references to the elements you're creating so that you can use them later (el.email and friends) but you also need to return them to the children function in an ordered manner so that it can actually attach t…
I'm still not sure how I feel about that bit of code though but it sure is clever...
Re: RE:DOM – Tiny DOM library
#8I've never seen this before: children(el => [ el.email = input(props({ type: 'email' })), el.pass = input(props({ type: 'pass' })), el.submit = button(text('Sign in')) ]) Can someone explains what this does and why it is used here? As i understand it this function both modifies the `el` object (whatever that is) and returns an array containing the input elements, but why would you want to do both those things at the…
const login = document.createElement('form');
login.email = document.createElement('input');
login.email.type = 'email';
login.pass = document.createElement('input');
login.pass.type = 'pass';
login.submit = document.createElement('button');
login.submit.textContent = 'Sign in';
login.appendChild(login.email);
login.appendChild(login.pass);
login.appendChild(login.submit);
login.onsubmit = function(event) {
event.preventDefault();
console.log(this.email.value, this.pass.value);
};
document.body.appendChild(login);
The children call produces an array of objects that are appended to the element, but the callback also takes the wrapping element (in this case `login`), and so to be conveniently able to access it later (`login.email.value`) it also assigns them there. A more conventional JavaScript approach would be to assign email, pass and submit as local variables rather than stuffing them inside the form object.As for the other example:
const app = document.createElement('table');
const tbody = document.createElement('tbody');
app.appendChild(tbody);
app.update = function(data) {
tbody.innerHTML = '';
for (let row in data.tbody) {
let tr = document.createElement('tr');
for (let cell in row) {
let td = document.createElement('td');
td.textContent = cell;
tr.appendChild(td);
}
tbody.appendChild(tr);
}
}
document.body.appendChild(app);
app.update({
tbody: [
[1, 2, 3],
],
});
This is rather simpler, frankly. I prefer plain DOM for myself at this level.Re: RE:DOM – Tiny DOM library
#9Re: RE:DOM – Tiny DOM library
#10I've never seen this before: children(el => [ el.email = input(props({ type: 'email' })), el.pass = input(props({ type: 'pass' })), el.submit = button(text('Sign in')) ]) Can someone explains what this does and why it is used here? As i understand it this function both modifies the `el` object (whatever that is) and returns an array containing the input elements, but why would you want to do both those things at the…
Here’s what I believe will be an accurate translation of that example to the normal DOM API (without having actually looked at the RE:DOM source code): const login = document.createElement('form'); login.email = document.createElement('input'); login.email.type = 'email'; login.pass = document.createElement('input'); login.pass.type = 'pass'; login.submit = document.createElement('button'); login.submit.textContent =…