5 ms·
lit-html lets you write declarative, reactive templates in plain JS, and is ~3.3k. Check it out here: https://lit-html.polymer-project.org https://lit-html.poly
by spankalee 7y ago
lit-html lets you write declarative, reactive templates in plain JS, and is ~3.3k. Check it out here: https://lit-html.polymer-project.org https://lit-html.polymer-project.org
- rbanffy 7y agoThat sayHello function declaration burns my eyes. Why?
- TeMPOraL 7y agoBecause it's the first time you've seen JS lambdas, the "html`foo`" syntax, and/or JS string interpolation? This function looks perfectly 100% normal to me, but that's probably I spent a whole workweek once almost entirely in ObservableHQ documents, where you'd use md`...`, html`...`, etc. all the time.
- rbanffy 7y agoIt's not the first time I see JS lambdas, or lambdas. I'm just not sure why let f = (a, b) => a + b can be considered prettier (or clearer) than let f = function (a, b) { return a + b } or (given the differences in runtime behavior) function f (a, b) { return a + b } It saves typing for trivial functions, sure, but it's yet another syntax for the same thing.
- spankalee 7y agoI prefer it for 1) Less tokens: less noise, more signal. `a + b` is the important part, let's not obscure it. 2) Lexical `this` binding. 3) Shorter and less likely to line-break. 4) No hoisting when used with let and const 5) Actually const when used with const. const module exports are faster.
- thrower123 7y agoI've come to like the arrow-function lambda syntax, but that's mostly because it is exactly what C# uses, and I write vastly more lambdas for LINQ and higher-order functions on the back-end than I do in JS. The only downside is you've got to involve babel to transpile it down to the shitty old browser versions that we need to support, so you go from a simple reload to a webpack or grunt invocation that takes 30 seconds to a couple minutes, depending on how invasive the corporate anti-virus is feeling today.
- spankalee 7y agoJust don't compile during development. Only compile for testing on and differential serving to legacy browsers.
- brylie 7y agoYeah, I was excited about Polymer when learning about Web Components. I'll read more about lit-element. Thanks :-)
- kreetx 7y agoI also like that it comes with no virtual dom, but just remembering direct references to the "holes" that need filling. It's funny that vdom has gotten so much traction albeit being inherently inefficient.