Class M.DataConsumer
Extends
M.Object.
A data consumer can be called a read-only data provider. It's only job is it to retrieve some data form
remote services, e.g. a webservice, and to push them into the store.
Note: So far we only support data in JSON format!
Defined in: data_consumer.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Field Attributes | Field Name and Description |
---|---|
This property can be used to specify whether or not to append any fetched
data sets to the existing records.
|
|
This property specifies the used http method for the request.
|
|
This property can be used to specify the path to the desired data within
the response.
|
|
The type of this object.
|
|
The urlParams property will be pushed to the url() method of your data
consumer.
|
Method Attributes | Method Name and Description |
---|---|
configure(obj)
Use this method within your model to configure the data consumer.
|
|
find(obj)
This method is automatically called by the model, if you call the model's
find().
|
|
map(obj)
Override this method within the data consumer's configuration, to map
the response object to your model's properties as follows:
map: function(obj) {
return {
userName: obj.from_user,
userImage: obj.profile_image_url,
createdAt: obj.created_at,
tweet: obj.text
};
}
|
|
url()
Override this method within the data consumer's configuration, to tell
the component which url to connect to and with which parameters as
follows:
url: function(query, rpp) {
return 'http://www.myserver.com/request?query=' + query + '&rpp=' + rpp
}
The parameters passed to this method are defined by the configuration
of your data consumer.
|
Field Detail
{Boolean}
appendRecords
This property can be used to specify whether or not to append any fetched
data sets to the existing records. If set to NO, the model's records are
removed whenever the find() method is called.
{String}
httpMethod
This property specifies the used http method for the request. By default
GET is used.
{String}
responsePath
This property can be used to specify the path to the desired data within
the response. Simply name the path by concatenating the path parts with
a '.', e.g.: 'path.to.my.desired.response'.
{String}
type
The type of this object.
{String}
urlParams
The urlParams property will be pushed to the url() method of your data
consumer. This should look like:
url: function(query, rpp) {
return 'http://www.myserver.com/request?query=' + query + '&rpp=' + rpp
}
Method Detail
configure(obj)
Use this method within your model to configure the data consumer. Set
resp. override all the default object's properties, e.g.:
{
urlParams: {
query: 'html5',
rpp: 10
},
appendRecords: YES,
callbacks: {
success: {
target: MyApp.MyController,
action: 'itWorked'
},
error: {
action: function(e) {
console.log(e);
}
}
},
map: function(obj) {
return {
userName: obj.from_user,
userImage: obj.profile_image_url,
createdAt: obj.created_at,
tweet: obj.text
};
}
}
- Parameters:
- {Object} obj
- The configuration parameters for the data consumer.
find(obj)
This method is automatically called by the model, if you call the model's
find(). To execute the data consuming processs imply pass along an object
specifying the call's parameters as follows:
{
urlParams: {
query: 'html5',
rpp: 10
}
}
These parameters will automatically be added to the url, using the
url() method of your data consumer.
Depending on the success/failure of the call, the specified success
resp. error callback will be called.
- Parameters:
- {Object} obj
- The options for the call.
map(obj)
Override this method within the data consumer's configuration, to map
the response object to your model's properties as follows:
map: function(obj) {
return {
userName: obj.from_user,
userImage: obj.profile_image_url,
createdAt: obj.created_at,
tweet: obj.text
};
}
- Parameters:
- {Object} obj
- The response object.
url()
Override this method within the data consumer's configuration, to tell
the component which url to connect to and with which parameters as
follows:
url: function(query, rpp) {
return 'http://www.myserver.com/request?query=' + query + '&rpp=' + rpp
}
The parameters passed to this method are defined by the configuration
of your data consumer. See the urlParams property for further information
about that.