datasource-debug.js revision 2fd0020b39d0935dd53b83d78bc7b3ca4007ed79
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * The DataSource utility provides a common configurable interface for widgets to
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * access a variety of data, from JavaScript arrays to online database servers.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @module datasource
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * Base class for the YUI DataSource utility.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @class DataSource.Local
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @extends Base
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @constructor
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright DSLocal.superclass.constructor.apply(this, arguments);
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright /////////////////////////////////////////////////////////////////////////////
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright // DataSource static properties
a7e9ca67d735ae1bcdc1f7deb35ab98dd9c9f614Derek Gathright /////////////////////////////////////////////////////////////////////////////
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * Class name.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @property NAME
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @type String
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @value "DataSource.Local"
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo /////////////////////////////////////////////////////////////////////////////
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright // DataSource Attributes
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright /////////////////////////////////////////////////////////////////////////////
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * @attribute source
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @description Pointer to live data.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @type MIXED
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @default null
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * Global transaction counter.
f6eaca952977579049a77179dc827c5fc1d6c808Derek Gathright * @property DataSource._tId
f6eaca952977579049a77179dc827c5fc1d6c808Derek Gathright * @type Number
f6eaca952977579049a77179dc827c5fc1d6c808Derek Gathright * Executes a given callback. The third param determines whether to execute
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * @method DataSource.issueCallback
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo * @param callback {Object} The callback object.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @param params {Array} params to be passed to the callback method
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @param error {Boolean} whether an error occurred
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright issueCallback: function (e) {
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright callbackFunc = (e.error && e.callback.failure) || e.callback.success;
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * Internal init() handler.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @method initializer
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo * @param config {Object} Config object.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * Internal destroy() handler.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @method destructor
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * This method creates all the events for this module.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @method _initEvents
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * Fired when a data request is received.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @event request
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @param e {Event.Facade} Event Facade.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @param o {Object} Object with the following properties:
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>request (Object)</dt> <dd>The request.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>callback (Object)</dt> <dd>The callback object.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @preventable _defRequestFn
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo //this.publish("request", {defaultFn: this._defRequestFn});
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright //this.publish("request", {defaultFn:function(e){
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright // this._defRequestFn(e);
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo this.publish("request", {defaultFn: Y.bind("_defRequestFn", this)});
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * Fired when raw data is received.
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * @event data
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo * @param e {Event.Facade} Event Facade with the following properties:
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>request (Object)</dt> <dd>The request.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>success (Function)</dt> <dd>Success handler.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>scope (Object)</dt> <dd>Execution context.</dd>
f6eaca952977579049a77179dc827c5fc1d6c808Derek Gathright * <dt>data (Object)</dt> <dd>Raw data.</dd>
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo * @preventable _defDataFn
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright //this.publish("data", {defaultFn: this._defDataFn});
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright //this.publish("data", {defaultFn:function(e){
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo // this._defDataFn(e);
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright this.publish("data", {defaultFn: Y.bind("_defDataFn", this)});
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * Fired when response is returned.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @event response
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @param e {Event.Facade} Event Facade with the following properties:
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>request (Object)</dt> <dd>The request.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>success (Function)</dt> <dd>Success handler.</dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
a7e9ca67d735ae1bcdc1f7deb35ab98dd9c9f614Derek Gathright * <dt>scope (Object)</dt> <dd>Execution context.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>data (Object)</dt> <dd>Raw data.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>response (Object)</dt> <dd>Normalized resopnse object with the following properties:
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>results (Object)</dt> <dd>Parsed results.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>error (Boolean)</dt> <dd>Error flag.</dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * @preventable _defResponseFn
a7e9ca67d735ae1bcdc1f7deb35ab98dd9c9f614Derek Gathright //this.publish("response", {defaultFn: this._defResponseFn});
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright //this.publish("response", {defaultFn:function(e){
a7e9ca67d735ae1bcdc1f7deb35ab98dd9c9f614Derek Gathright // this._defResponseFn(e);
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright this.publish("response", {defaultFn: Y.bind("_defResponseFn", this)});
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * Fired when an error is encountered.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @event error
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @param e {Event.Facade} Event Facade with the following properties:
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>request (Object)</dt> <dd>The request.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>success (Function)</dt> <dd>Success handler.</dd>
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>scope (Object)</dt> <dd>Execution context.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>data (Object)</dt> <dd>Raw data.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>response (Object)</dt> <dd>Normalized resopnse object with the following properties:
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>results (Object)</dt> <dd>Parsed results.</dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>error (Object)</dt> <dd>Error object.</dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * Manages request/response transaction. Must fire <code>response</code>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * event when response is received. This method should be implemented by
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * subclasses to achieve more complex behavior such as accessing remote data.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @method _defRequestFn
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @param e {Event.Facade} Event Facadewith the following properties:
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>request (Object)</dt> <dd>The request.</dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>success (Function)</dt> <dd>Success handler.</dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>scope (Object)</dt> <dd>Execution context.</dd>
_defRequestFn: function(e) {
if(e.error) {
_defDataFn: function(e) {
response = {
_defResponseFn: function(e) {
return tId;
var DSXHR = function() {
ATTRS: {
io: {
* cycles enabled if queue needs to be managed (asyncMode/xhrConnMode):
_queue: null,
_defRequestFn: function(e) {
cfg = {
on: {
context: this,
arguments: e
return e.tId;
var DataSourceCache = function() {
ATTRS: {
_beforeDefRequestFn: function(e) {
_beforeDefResponseFn: function(e) {
var DataSourceJSONSchema = function() {
ATTRS: {
schema: {
_beforeDefDataFn: function(e) {
var data = ((this.get("host") instanceof Y.DataSource.XHR) && Y.Lang.isString(e.data.responseText)) ? e.data.responseText : e.data,
if(!response) {
response = {
meta: {},
var DataSourceXMLSchema = function() {
ATTRS: {
schema: {
_beforeDefDataFn: function(e) {
var data = ((this.get("host") instanceof Y.DataSource.XHR) && e.data.responseXML && (e.data.responseXML.nodeType === 9)) ? e.data.responseXML : e.data,
if(!response) {
response = {
meta: {},
Pollable = function() {
this._intervals = {};
_intervals: null,
return x.id;
clearAllIntervals: function() {