Re:Agility.js - Javascript MVC for the "write less, do more"...
by delambo on Friday July 22, 2011 @07:08PM
(#2795517)
If this solves your problem, then you probably didn't need MVC in the first place. But this doesn't necessarily decouple you from the DOM, and it sounds like all of the code that works with these models is a bunch of jQuery callbacks hooked into the DOM. Is that right?
If so, and your project is sizable, then an MVC, like backbone.js, could be beneficial.
Re:Agility.js - Javascript MVC for the "write less, do more"...
by JesseAldridge on Friday July 22, 2011 @07:28PM
(#2795567)
The code can work with the models without touching the DOM. You just access the models via ids.
eg
parent_model = window.models[foo_model.get('parent_id')]
parent_model.set('text', 'foo text')
When you respond to a button click or whatever, then yeah, you use a jQuery callback. The model id is stored in the DOM element (the view) which you access with $(this). Whenever the model changes (via set), the render function is automatically called. The render function is responsible for passing attributes to a template which renders html. Then the render function sticks the html wherever it's supposed to go. I think that's basically how all MVC frameworks work under the hood.
Re:Agility.js - Javascript MVC for the "write less, do more"...
by vhackish on Saturday July 23, 2011 @01:19PM
(#2797303)
Looked at backbone.js and thought the same thing - overkill for what I needed. I'm always thinking "how will I scale this to portable devices", and one important consideration is code size. Plus IMHO HTML/JavaScript/CSS is quite MVC to begin with (HTML/CSS being the View, JavaScript of course is Controller logic, and just don't make the mistake of using the DOM as your data storage and use JavaScript objects for the Model). Maybe it depends on the complexity of the app, and I'd definitely look at agility.js first if I needed something since it's lighter than backbone.js ...
Here's how I'm currently doing it:
Now, that doesn't do much. But for prototyping a gui, it seems pretty good. Less is more. I wonder how little code I can add to get it to work with a real backend.