Friday, August 3, 2012

Knockout

Yesterday I spent a while running through the tutorials offered on the site for the Knockout Javascript library. Knockout's concept is what they call MVVM; I'd never really heard of that particular acronym, and while I initially thought it was a bit awkward, I do understand what they're driving at.

Knockout is purely client-side, so it remains open to work with whatever method you use to provide data from your server. It just wants JSON, which is fine because that's what I was planning on. But while it's a client library, it isn't trying to be a flashy effects library like Prototype or even a utility belt like JQuery. In fact, it seems to play nicely if you also want to use other libraries like that. It focuses on one concept and tries to do that well, which I like.

What Knockout concentrates on is the problem of keeping a UI in sync with data. I appreciate this, because I remember that a lot of time I've spent while writing Ajax-oriented apps has been centered around getting the newly-received server data into the right part of the page. Knockout makes it automatic. You have your model in the server, and when it comes over to the client it becomes the "view model". Then, instead of having to find the right
or whatever and put the data there, Knockout keeps it all synchronized for you. This works because of a few things you did at page startup: you set up an internal representation of the data (view model), marked some of those data as observable, and bound certain elements in your page as to portions of that data by using special html attributes.


And how does the data gets from the server to the client? They seem to want to that leave to other libraries like JQuery.

Their homepage contains some really cool interactive tutorials that show off the functionality. Overall I was impressed, and I could see this library becoming part of the stack I use to build my app.

No comments:

Post a Comment