A view’s responsibility — a lesson on JavaScript and the DOM
open.bekk.no
open.bekk.no
Edit: The blog appears to be up again! Hopefully it'll stay up this time ;)
No framework or library is needed, but they help. And at ~5k both Backbone and Spine's DOM-management object (resp. View and Controller) provide exactly the behavior (and shortcuts) you talk about.
Edit: Added! Thanks. I should absolutely have added that before posting it.
Aye, absolutely, just wanted to nitpick on that statement: while it is technically true (still the best kind around), it can be... not sure what the word is, not quite misleading but it can cause people to waste time not using a library when a small one would do that job (and others) for them.
It's absolutely great that you clearly documented the "pattern" as it is a vital one to retain one's sanity, it's just that this phrase sounded like an unwarranted objection to libraries doing the exact thing you recommend :)
[0] for instance both Backbone and Spine provide a declarative mapping of events triggered within a view's DOM to a method of that view, making handling of events arising from one's DOM much easier than handling events from outside; Spine also provides a mapping for sub-elements of a view's DOM automatically setting them on attributes of the view making DOM manipulation itself simpler.
I put together some similar thoughts on client side code organization a while back: http://happybearsoftware.com/client-side-field-notes.html
What you get is loosely coupled, highly testable (and fast tests, since dom stuff is all in memory) ui code.