by qud · 10y ago · 0 comments
I would really appreciate it if you'd share the application structure you use when building a client side MVC with vanilla JS/Jquery.
I know there wouldn't be a single structure to rule them all, but I think if developers start sharing structures that work regardless of frameworks used, it would be much better than sharing frameworks that are very complex and get replaced every year.
Views are very simple. There is generally a class instance which is using a DOM element somewhere. So I store a reference to that element on the instance. Then I have a simple object containing references to all of the important elements within it. I have a function which generates the element if it hasn't been created yet and adds it to the page. Now I can change whatever I want to about the element or any important elements within it. I use classes like "is-hidden."
Sometimes I'll decouple the UI from it's functionality. In which case I usually implement a simple eventer system on the underlying code which the UI connects to for status updates.
Bingo bango. I haven't run into a circumstance yet where any one file was longer than maybe 200-300 lines total. It's simple to read, it does anything I want.
I have never needed to construct anything client side that warranted laying it out like a server implementation. But maybe that's my issue, I'm thinking too small and other people have a better idea of what the future of the web looks like than me.
I still prefer having control.