1marc / modern-todomvc-vanillajs Goto Github PK
View Code? Open in Web Editor NEWTodoMVC with Modern (ES6+), Vanilla JavaScript
Home Page: https://frontendmasters.com/blog/vanilla-javascript-todomvc/
TodoMVC with Modern (ES6+), Vanilla JavaScript
Home Page: https://frontendmasters.com/blog/vanilla-javascript-todomvc/
One issue with vanilla JS is that your selectors get tightly coupled to the generated DOM.
The more I think about this, something like:
<div data-jsmodule="behavior"></div>
document.querySelector('[data-jsmodule="behavior"]')
Would work better for selectors since now you can move the data attributes around to hook the JS into it not worry as much about the actual markup.
Recap of where I’m at with the TypeScript branch: https://github.com/1Marc/todomvc-vanillajs-2022/tree/typescript/js
Spent a few minutes getting the compiler happy (though some of this is quite hacky) but here's what's next:
EventTarget
$
(like $.list
) and having DOM modification methods (like $.setActive
) is overloading which means you need a union type Function | HTMLElement
then cast as you call the methods so there’s got to be a way to prefix DOM method keys, or we can simply give them their own namespaceThis was a naive "satisfy the compiler" stab just get it working. Trying to build a base that works to start making a nicer solution.
It looks like there is no difference.
But it's still nice to read the simple .slice(1)
This is a fun project! Thanks for creating and sharing it.
I may be overlooking it, but I don't see a link I can click to test this (without downloading the repo). I'm on my phone, and it would be nice to have a link to a live version of this.
Consider enabling GitHub Pages for this repo and linking to that URL in the project description and/or readme.
Why did you decide not to use web components? Use of shadow DOM might not be needed (although it couldn't hurt either), but custom elements might be a nice addition.
Current behavior:
When you toggle an item, since it's re-rendered, the focus is be lost.
Expected behavior:
Focus remains on the checkbox or label when toggling.
Additional context:
I think this is a common problem with naive declarative UI implementations. React, at least, doesn't seem have this problem with its sophisticated virtual DOM.
Btw, if you're interested, I took a stab at recreating TodoMVC in vanilla JavaScript with Web Components, with a somewhat unorthodox approach: https://github.com/johnfactotum/todomvc
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.