datasource-dataparser.js revision 9eb0c723ed90ba9c691cd35c025115b361da3eb4
/**
* Extends DataSource.Base with schema-based parsing functionality.
*
* @module datasource-dataparser
* @requires datasource-base,dataparser-base
* @title DataSource DataParser Extension
*/
var LANG = Y.Lang,
BASE = Y.DataSource.Base,
/**
* Adds parsability to the YUI DataSource utility.
* @class Parsable
*/
Parsable = function() {};
Parsable.ATTRS = {
/////////////////////////////////////////////////////////////////////////////
//
// DataSource.Base Attributes
//
/////////////////////////////////////////////////////////////////////////////
/**
* Instance of DataParser.
*
* @attribute parser
* @type Y.DataParser.Base
* @default null
*/
parser: {
value: null,
validator: function(value) {
return ((value instanceof Y.DataParser.Base) || (value === null));
}
}
};
Parsable.prototype = {
/**
* Overriding responseEvent handler parses raw data response before sending
* to returnData().
*
* @method _handleResponse
* @protected
* @param args.tId {Number} Transaction ID.
* @param args.request {MIXED} Request.
* @param args.callback {Object} Callback object.
* @param args.response {MIXED} Raw data response.
*/
_handleResponse: function(args) {
var response = args.response;
response = (this.get("parser") && this.get("parser").parse(response)) || {results: response};
this.returnData(args.tId, args.request, args.callback, response);
}
};
Y.Base.build(BASE, [Parsable], {
dynamic: false
});