Hacker News new | ask | show | jobs
by qud 3627 days ago
Wow I never thought I'll see someone else with my same concern. I really hate using too much third-party code (to the point that I need a generator just to start), and I like knowing what each and every file in my project is for/does.

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.

1 comments

I create a separate file for each concern, and I dump them into the same directory together. If the files list become significantly long I separate them into subfolders of more general concerns. For example a folder for everything to do with "recording" functionality.

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.