Loosely said, the various components in a MVVM pattern are
Model
: this represents the data send by the server and sent back to the server. this contains no state related to display of the UIViewModel
: this is constructed from one or models. this contains state meant for UI manipulation (is the button enabled or disabled). all logic meant for UI manipulation is stored here. this layer has no dependency on any UI framework (no jQuery calls)View
: this has tight coupling with the UI framework/underlying UI controls. One view observes one and only one view model. A view model can be observed by one or more views. The view is responsible for doing two-binding with the view model.- A
presenter/coordinator
: While not a part of the traditional implementation, in its absence the view model ends up with way too much responsibility. This guy helps coordinate making ajax calls (get/post), listening to events on the global event aggregator etc
Standalone Backbone has no concept of view models and data binding. In that scenario, the data returned by the server can be modelled as Backbone.Model
objects. The bindings are done manually and a POJO can be used for view-model syncing.
If I wish to use Stickit for data binding, it appears that the view model needs to be an instance of Backbone.Model
. Chiefly because the bindings work within the context of a Backbone.View
and a Backbone.View
expects a Backbone.Model
object to be present as a property of the view. Also, a Backbone.Model raises change events and what not. I assume it will be difficult to observe a POJO. Again, this is my understanding from reading the Stickit docs. Please correct me if I am wrong.
A Backbone.Model
has other methods on it that don't make sense from the point of view of a view model, like save
, fetch
etc. I was reading up on another mvvm library, Knockback
. It can transform a Backbone.Model
into a Knockout.js
view model. Instead of passing in a full fledged Backbone.Model
, it can also accept any POJO that has get/set methods and raises change events when the properties have changed.
Does Stickit have a similar contract wherein I can pass in a POJO that has get/set methods and raises change events? What is the recommended usage?