| ▲ | mholt 2 days ago |
| I'm using the <template> tag heavily in Timelinize[0], which has a fairly sophisticated UI that I'm writing in vanilla JS -- not even jQuery. I use a few libraries (for mapping, datetime, and Bootstrap+Tabler for some nice styles), but that's it. I wrote some boilerplate JS, yes, but I have complete control over my frontend, and I understand how it works, and I don't need to compile it. Anyway, it works well so far! The <template> tag is a great way to lay out components and then fill them in with simple JS functions. One nuance is documented in my code comments: // Ohhhhhh wow, we need to use firstElementChild when cloning the content of a template tag (!!!!):
// https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/template#avoiding_documentfragment_pitfalls
// I spent way too long on this.
const elem = $(tplSelector);
if (!elem) return;
return elem.content.firstElementChild.cloneNode(true);
Once I figured that out, it's been smooth sailing and very powerful.Oh, but I haven't cleaned up my code at all yet because I was just experimenting/hustling, so it's a bit spaghetti :) If you go looking, don't mind the mess. --- [0]: https://github.com/timelinize/timelinize - a self-hosted application for bringing together all your data on your own computer and organizing it onto a single timeline: social media accounts, photo libraries, text messages, GPS tracks, browsing history, and more. Almost ready for its debut... |
|
| ▲ | jfagnani 2 days ago | parent | next [-] |
| You should use document.importNode() to clone templates. Template contents are in a separate document from the main document, which is what makes them inert. importNode() adopts the nodes into the document so they have the correct prototype immediately (which includes custom elements). Otherwise the adopt steps are run when the elements are first attached to the document, which adds another tree walk to the insert/append operation that costs some time. So: document.importNode(elem.content, true);
Then you'll have a DocumentFragment you can pull nodes out of. Or just append the whole fragment. |
| |
| ▲ | mholt 2 days ago | parent [-] | | Awesome -- gonna try this. Thanks for the tip! And lit-html looks cool btw. Update: I'm using importNode() now -- works great too. |
|
|
| ▲ | mikae1 2 days ago | parent | prev | next [-] |
| Timelinize, just wow. Been wishing for something like this forever. Love the idea! Regarding the gpx support... Don't want to lead you astray, but, have you seen https://www.sethoscope.net/heatmap/? |
| |
| ▲ | mholt 2 days ago | parent [-] | | Thanks! Hopefully it delivers. I haven't seen that, actually -- looks very nice. We do render a heatmap already, but I'm learning that heatmaps are very tricky to tune to be most useful/interesting. I will try to learn from that project. |
|
|
| ▲ | mariusor 2 days ago | parent | prev | next [-] |
| I considered vanilla template initially for building my ActivityPub frontend[1], but in the end the sugar that lit-js adds on top of web components seemed worth the file size overhead. [1] https://github.com/mariusor/oni |
| |
| ▲ | jfagnani 2 days ago | parent [-] | | Author of lit-html here. Yeah, Lit's tagged template literals and render() method are basically a shorthand for making a <template> element, marking the spots where expressions go, cloning the template, then filling in those sports. |
|
|
| ▲ | WorldMaker 2 days ago | parent | prev | next [-] |
| > I use a few libraries (for mapping, datetime I'm really looking forward to Temporal [0] reaching a larger baseline. Between that and a lot of recent Intl pieces we are so close to not needing libraries for much of anything datetime related. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... |
| |
| ▲ | mholt a day ago | parent [-] | | Yeah, dealing with date/time in JS has been a HUGE pain. I haven't tried Temporal yet but I hope it's better. | | |
| ▲ | WorldMaker a day ago | parent [-] | | I've used it a bit already. You can use it with an experimental flag in Deno. It takes a lot of inspiration (from among others) from the java.time library added in Java 8+ in a similar way that JS' original Date class is related to the very original Java Date class, so it basically catches up on 8+ versions of Java. It supports just about all the Date math, comparison, and calendar conversion you could ever want. It has nice toLocaleString() formatting options. It's built on immutable objects to avoid a whole class of bugs with the current JS Date. |
|
|
|
| ▲ | freedomben 2 days ago | parent | prev | next [-] |
| Dude, cool project! I considered building something like this a couple years ago as the only way in hell I'd ever use it is if it's open source and self-hosted (thanks so much for using AGPLv3!). I ended up stuck in analysis paralysis, so I'm super impressed :-) |
| |
| ▲ | mholt 2 days ago | parent [-] | | Ha, thanks. It's hard, so no shame for being "stuck". I've iterated on this for over a decade at this point. Still more evolution to come... but I really want this for my family. |
|
|
| ▲ | Lord_Zero 2 days ago | parent | prev | next [-] |
| What's Tabler? |
| |
| ▲ | mholt 2 days ago | parent [-] | | It's this: https://tabler.io/admin-template Still highly unstable between versions, but for being free, it looks really good and is very flexible. I've been pleased with it for this project. | | |
| ▲ | WorldMaker 2 days ago | parent [-] | | Seems to me a lot of what Tabler does you could do easily today in "vanilla" CSS Grid, which is also even more flexible. (I have done some very dynamic dashboards with simple CSS class changes and CSS Grid. You can do so much just changing grid-template-areas, and I really like its feel as an ASCII diagram of the layout that you want so I think it's also easy to scan a lot of layout variations in a CSS file to see which one is which.) At this point I've been ditching almost every other type of layout (Bootstrap's Grid, Flexbox, etc) in most places for just "vanilla" CSS Grid and I think it is fantastic. I think it is well worth learning if you haven't yet. | | |
| ▲ | mholt a day ago | parent [-] | | I use grid (still find it hard to grok though) -- but Tabler is more than just layout/flow. I like Tabler's component styles and it's highly customizable and easy to use, which I appreciate. |
|
|
|
|
| ▲ | cyanydeez 2 days ago | parent | prev [-] |
| It's almost guaranteed this will be used for unwanted surveillance. |
| |
| ▲ | mholt 2 days ago | parent [-] | | It doesn't actually get any of your data, let alone anyone else's. It's just an organizer, so please elaborate. |
|