News for hackers. Stuff that matters.
Re:Knockout: JS library for rich UIs, declarative bindings, ... by equark on Wednesday October 20, 2010 @12:53PM (#1811885)
I considered both Backbone and Knockout and ended up with Knockout, although both are great! I find Knockout's simple declarative binding to be cleaner for most cases:

  <span data-bind:"text: title"></span>
And Knockout allows you to put bindings in code too, where that makes sense. I also like the way Knockout keeps everything in the view model, rather than passing in the observable attributes when constructing an instance. For instance:

  var Sidebar = Backbone.Model.extend({
    promptColor: function() {
      var cssColor = prompt("Please enter a CSS color:");
      this.set({color: cssColor});
    }
  });
Here color doesn't exist yet. I guess this is just standard javascript style? In Knockout (+coffeescript), I'd write:

  class SideBar
    color: ko.observable('white')
    promptColor: ->
       @color(prompt('Please enter CSS color:'))
My model is self-contained. This example also shows the syntax for updating and getting values. I prefer Knockout's

  @color(cssColor)
to Backbone's

@set({color: cssColor})

although this is minor and perhaps you want to allow for bulk updates.

I can't help but feel that these types of libraries are the future. I hope there is lots of cross-pollination going on. Sproutcore focuses on the 5 percent of webapps that should be desktop style. Both Knockout and Backbone give lots of the same benefits, but allow a more flexible application style.

My only wish is for a language agnostic persistence protocol, with some socket.io and REST protocols implemented for most frameworks/languages. Ideally, I could use this protocol to sync with my iPhone/Android/HTML5 app, without changing the server side. This could get very hairy (FeedSync/LiveMesh/Wave), but something simple that accomplishes 90% would be a great.

There are no comments on this comment yet.