Single Page Web Applications - part one
petermartinblog.com
petermartinblog.com
My question to the community in this thread is, why all these new JS libraries? Do they offer something that I don't know about, something jquery doesn't?
He didn't even mention jquery in his post, yet he mentioned a ton of other libraries I had never heard of before. So I'm very curious.
If the state does become global, then you will have all the struggles that come with that ... something will change "foo" in the global state, and that will cause problems in some completely unrelated part of the page, which will take you hours/days to track down. This is just one example of the kind of problem you can experience.
What the Single Page App frameworks offer is a nicer way to organize all this complexity. You have models, which can fire events. You have Controllers, which (though defined differently in each framework) help you capture and express event listeners in one well-managed location. And you have views to generate changes to the HTML, which usually have enough integration with the models that it greatly reduces the amount of event handling/template re-generation code you have to write.
They really do make a difference, and the MVC frameworks that are out there these days are excellent. I guess the only real way to get a handle on what they do for you is to try a quick demo.
http://blog.stevensanderson.com/2012/08/01/rich-javascript-a...
http://codebrief.com/2012/01/the-top-10-javascript-mvc-frame...
As far as routing goes, I use Backbone.router. I've written more about why we chose this setup on my blog: http://www.rivvir.com/for-us-for-now-knockout-js-backbone-ro...
When you want to rapidly develop an all with two way data-binding, dynamic views, and a little bit of XHR, declarative-friendly JavaScript frameworks like Angular and Knockout really shine.
<html> <head> <script type='text/javascript' src='knockout-2.2.1.js'></script> </head> <body> <!-- This is a view - HTML markup that defines the appearance of your UI -->
<p>First name: <strong data-bind="text:firstName">todo</strong></p> <p>Last name: <strong data-bind="text:lastName">todo</strong></p>
<script type="text/javascript"> // This is a simple viewmodel - JavaScript that defines the data and behavior of your UI function AppViewModel() { this.firstName = "Bert"; this.lastName = "Bertington"; }
// Activates knockout.js ko.applyBindings(new AppViewModel()); </script> </body> </html>