News for hackers. Stuff that matters.
Re:RE:DOM – Tiny DOM library by ams6110 on Sunday August 28, 2016 @07:20PM (#12379020)
Honest question, how is:

  el.email = input(props({ type: 'email' }))
better or easier than:

  <input type="email">
I think the example needs to be more compelling.
Re:RE:DOM – Tiny DOM library by zachrose on Sunday August 28, 2016 @08:30PM (#12379265)
I assume you mean to compare it to:

    el.email = (function(){
        var input = document.createElement('input');
        input.type = "email";
        return input;
    })();
...or something similar. Your could also use createContextualFragement or a little function that uses innerHTML, both of which parse a string into HTML (which is problematic). Or you could use a templating library, of which there are many and this is one.
Re:RE:DOM – Tiny DOM library by megous on Sunday August 28, 2016 @08:59PM (#12379349)

    el.email = document.createElement('input');
    el.email.type = "email";
Re:RE:DOM – Tiny DOM library by AgentME on Sunday August 28, 2016 @10:17PM (#12379577)

    el.email = Object.assign(document.createElement('input'),{type:'email'});
Re:RE:DOM – Tiny DOM library by ErikHuisman on Monday August 29, 2016 @01:43AM (#12380218)
el.email = { document.createElement('input'), ...{ type: 'email' }}
Re:RE:DOM – Tiny DOM library by AgentME on Monday August 29, 2016 @11:20PM (#12387273)
I know about the spread operator, but I'm pretty sure that's invalid. `var foo = { document.createElement('input') };` doesn't work, spread or no spread after it.
Re:RE:DOM – Tiny DOM library by ErikHuisman on Tuesday August 30, 2016 @02:17PM (#12392500)
Ow man.. I saw the Object.assign example and thought i don't like it because it requires an extra polyfill. I can just use a spread and let babel handle it.

If anything it should be `var email = {...document.createElement('input'), type: 'email'}`

But that would result in `Object.assign({}, document.createElement('input'), { type: 'email' })`

Got 4 up votes though..

Re:RE:DOM – Tiny DOM library by klibertp on Monday August 29, 2016 @06:33AM (#12381036)
What supports this feature and how is it implemented?
Re:RE:DOM – Tiny DOM library by yawgmoth on Monday August 29, 2016 @06:49AM (#12381089)
Re:RE:DOM – Tiny DOM library by yawgmoth on Monday August 29, 2016 @11:28AM (#12382509)
(Too long to edit my other reply)

Also used was object destructuring: http://odetocode.com/blogs/scott/archive/2014/09/11/features...

Re:RE:DOM – Tiny DOM library by sanbor on Sunday August 28, 2016 @08:53PM (#12379330)
$('<input type="email">')
Re:RE:DOM – Tiny DOM library by mkoryak on Sunday August 28, 2016 @11:50PM (#12379895)
I recently had the pleasure of tracking down the source code for how this works. There are a few methods, but the main one is at least a hundred lines long.
Re:RE:DOM – Tiny DOM library by ghayes on Monday August 29, 2016 @03:22AM (#12380539)
Why did you wrap that in a closure / immediately invoked function expression?
Re:RE:DOM – Tiny DOM library by wingless on Monday August 29, 2016 @06:43AM (#12381069)
It's a way of hiding local variables. Old "var" variables are function scoped, so you can't even hide them in if-blocks or for-blocks, which makes scope leakage even worse.

If you're a JS programmer you should definitely read Crockford's famous JS book, it explains a lot of JS patterns and the rationale behind them.

Re:RE:DOM – Tiny DOM library by ars on Monday August 29, 2016 @01:32AM (#12380198)
Why compare it to that? There is no reason to avoid innerHTML anymore - it's not slow at all.

There is rarely a reason to build HTML using createElement, it's only sometimes needed. The majority of the time just write HTML - it's much easier.

> Or you could use a templating library

Or just use the built in <template> tag.

Re:RE:DOM – Tiny DOM library by exomancer on Monday August 29, 2016 @03:58AM (#12380636)
Not slow compared to what? Creating elements with the DOM API is faster than innerHTML roughly by a factor of 4 on Chrome Canary last I benchmarked it, DOM mutations with bindings are even faster. There is a reason why React switched from innerHTML to generating DOM.
Re:RE:DOM – Tiny DOM library by localvoid on Monday August 29, 2016 @04:37AM (#12380744)
>Creating elements with the DOM API is faster than innerHTML roughly by a factor of 4 on Chrome Canary last I benchmarked it

yes, almost by a factor of 4 :D

check out "render" test cases:

https://cdn.rawgit.com/localvoid/dd96890b82f1d1268df34330b14...

Re:RE:DOM – Tiny DOM library by pkstn on Monday August 29, 2016 @01:45AM (#12380226)
Template libraries are fine, but there are cases where you hope you could just write JavaScript..
Re:RE:DOM – Tiny DOM library by pkstn on Monday August 29, 2016 @01:43AM (#12380221)
When you build large applications, things are not always that simple.. If you want to be able to init the app and then start to update it with minimal work and maximum performance, HTML itself is not enough.
Re:RE:DOM – Tiny DOM library by korynunn on Sunday August 28, 2016 @10:37PM (#12379630)
Using crel as a comparison:

var input = crel('input', {type:'email'});

vs:

var wrapper = document.createElement('div'); wrapper.innerHTML = '<input type="email">'; var input = wrapper.children[0];

Re:RE:DOM – Tiny DOM library by mkawia on Sunday August 28, 2016 @08:17PM (#12379228)
angle brackets ,we decided long time ago we hate those :)
Re:RE:DOM – Tiny DOM library by sotojuan on Sunday August 28, 2016 @09:06PM (#12379373)
No we didn't, considering a lot of us write JSX at our jobs.
Re:RE:DOM – Tiny DOM library by timv on Monday August 29, 2016 @04:45AM (#12380763)
Both can be true - they certainly are in my case.
Re:RE:DOM – Tiny DOM library by joesb on Sunday August 28, 2016 @11:21PM (#12379798)
In general case, (for all other props), please don't forget to escape a quote in you prop's values.