question on model/view binding with cola

33 views
Skip to first unread message

Ilayaperumal Gopinathan

unread,
Jan 23, 2013, 12:37:35 PM1/23/13
to
I am trying to understand some of the cola concepts and would need some help to get it right.

Following is the step by step process I am trying to do to achieve model view binding:

1) Define cola 'Hub/Base' object: either Model or Collection
2) Bind this cola object to the view component and my bind facet has the following options:
                        to: (cola object created at step 1)
                        bindings: (some of the DOM handlers)
3) Bind the cola object(from step1) to the item data. Here I want to bind my model that is set from a REST API to this cola object.

Here are my questions:

Should I always have the cola adapters (from cola/adapter/) bind to the cola object that in turn connect to the actual model (from my Step3)?
For example, the cola ArrayAdapter uses a data array to create the ArrayAdapter object and we can make this bind to the cola 'Hub/Base' object.
In my wirespec, I am doing something like this:

colaCollection: {
     create: { module: 'cola/Collection' }
}

view1: {
     render: {...},
     bind: {
        to: {
           $ref: 'colaCollection'
        },
        bindings: { some DOM Handlers here }
     }
}

dataSourceArray: {
      create: {
          module: 'cola/adapter/Array',
          args: [ { $ref: 'Controller.thatReturnsDataArray' } ]
      },
      bind: {
          to: { $ref: 'colaCollection' }
      }
}

dataSourceQuery: {
       create: {
          module: 'cola/adapter/Query',
          args: [ { $ref: 'Controller.thatImplementsqueryfunction' } ]
      },
      bind: {
          to: { $ref: 'colaCollection' }
      }
}

Here, the controller's query function does the REST request to get the data.

The way I understand this from some of the demo apps: the cola adapters(cola/adapter/Array, Object, LocalStorage, Query etc.,) act as the data source and the DOM adapters (Node, NodeList) act as the destination.

A bit of explanation on the overview on how to define the cola binding to view and model would very much help!

Thanks in advance,
-- Ilaya
Message has been deleted

Ilayaperumal Gopinathan

unread,
Jan 23, 2013, 12:45:49 PM1/23/13
to cuj...@googlegroups.com
To add more details to my question:

There are providers and consumers defined in cola. 

Are the providers correspond to source adapters and the consumers correspond to destination adapters?

If I choose to use the cola Collection, then it has the adapters Array, NodeList and Query defined. 
Are the Array and Query adapters are source and NodeList is the destination adapters if I bind to choose my model and view to cola Collection.

Please correct if this understanding is correct. 



unscriptable

unread,
Jan 24, 2013, 10:09:42 AM1/24/13
to
Hey Ilaya,

By default, ArrayAdapter and QueryAdapter are providers and NodeListAdapter is a consumer.  You can change this behavior with an additional property in the bind facet.  Actually, if you're including both the ArrayAdapter and QueryAdapter in your example, you probably want to make the ArrayAdapter a consumer unless you're intentionally mixing their items together.  Example:

dataSourceArray: {
      create
: {
         
module: 'cola/adapter/Array',
          args
: [ { $ref: 'Controller.thatReturnsDataArray' } ]
     
},
      bind
: {

          to
: { $ref: 'colaCollection' },
          provide
: false // here's the magic keyword
     
}
}

-- John
Reply all
Reply to author
Forward
0 new messages