datasource-local.js revision 14ea8dcb06b6d844dd99b7e18cca99172bea0cfd
1255N/A * The DataSource utility provides a common configurable interface for widgets to 1255N/A * access a variety of data, from JavaScript arrays to online database servers. * Provides the base DataSource implementation, which can be extended to * create DataSources for specific data protocols, such as the IO Utility, the * Get Utility, or custom functions. * @submodule datasource-local * Base class for the DataSource Utility. * @class DataSource.Local ///////////////////////////////////////////////////////////////////////////// // DataSource static properties ///////////////////////////////////////////////////////////////////////////// * @value "dataSourceLocal" ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// * @description Pointer to live data. * Global transaction counter. * @property DataSource._tId * Global in-progress transaction objects. * @property DataSource.transactions * Returns data to callback. * @method DataSource.issueCallback * @param e {EventFacade} Event Facade. * @param caller {DataSource} Calling DataSource instance. //TODO: this should be executed from a specific context * Internal init() handler. * @param config {Object} Config object. * This method creates all the events for this module. * Fired when a data request is received. * @param e {Event.Facade} Event Facade with the following properties: * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd> * <dt>request (Object)</dt> <dd>The request.</dd> * <dt>callback (Object)</dt> <dd>The callback object * (deprecated, refer to <strong>on</strong></dd> * <dt>on (Object)</dt> <dd>The map of configured callback * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> * @preventable _defRequestFn * Fired when raw data is received. * @param e {Event.Facade} Event Facade with the following properties: * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd> * <dt>request (Object)</dt> <dd>The request.</dd> * <dt>callback (Object)</dt> <dd>Deprecated alias for the * <strong>on</strong> property</dd> * <dt>on (Object)</dt> <dd>The map of configured transaction * callbacks. An object with the following properties: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> * <dt>data (Object)</dt> <dd>Raw data.</dd> * @preventable _defDataFn * Fired when response is returned. * @param e {Event.Facade} Event Facade with the following properties: * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd> * <dt>request (Object)</dt> <dd>The request.</dd> * <dt>callback (Object)</dt> <dd>Deprecated alias for the * <strong>on</strong> property</dd> * <dt>on (Object)</dt> <dd>The map of configured transaction * callbacks. An object with the following properties: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> * <dt>data (Object)</dt> <dd>Raw data.</dd> * <dt>response (Object)</dt> * <dd>Normalized response object with the following properties: * <dt>results (Object)</dt> <dd>Parsed results.</dd> * <dt>meta (Object)</dt> <dd>Parsed meta data.</dd> * <dt>error (Boolean)</dt> <dd>Error flag.</dd> * <dd>Any error that occurred along the transaction lifecycle.</dd> * @preventable _defResponseFn * Fired when an error is encountered. * @param e {Event.Facade} Event Facade with the following properties: * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd> * <dt>request (Object)</dt> <dd>The request.</dd> * <dt>callback (Object)</dt> <dd>Deprecated alias for the * <strong>on</strong> property</dd> * <dt>on (Object)</dt> <dd>The map of configured transaction * callbacks. An object with the following properties: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> * <dt>data (Object)</dt> <dd>Raw data.</dd> * <dt>response (Object)</dt> * <dd>Normalized response object with the following properties: * <dt>results (Object)</dt> <dd>Parsed results.</dd> * <dt>meta (Object)</dt> <dd>Parsed meta data.</dd> * <dt>error (Object)</dt> <dd>Error object.</dd> * <dd>Any error that occurred along the transaction lifecycle.</dd> * event when response is received. This method should be implemented by * subclasses to achieve more complex behavior such as accessing remote data. * @param e {Event.Facade} Event Facadewith the following properties: * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd> * <dt>request (Object)</dt> <dd>The request.</dd> * <dt>callback (Object)</dt> <dd>Deprecated alias for the * <strong>on</strong> property</dd> * <dt>on (Object)</dt> <dd>The map of configured transaction * callbacks. An object with the following properties: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> Y.
log(
"Local source undefined",
"error",
"datasource-local");
Y.
log(
"Transaction " + e.
tId +
" complete. Request: " +
* Normalizes raw data into a response that includes results and meta properties. * @param e {Event.Facade} Event Facade with the following properties: * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd> * <dt>request (Object)</dt> <dd>The request.</dd> * <dt>callback (Object)</dt> <dd>Deprecated alias for the * <strong>on</strong> property</dd> * <dt>on (Object)</dt> <dd>The map of configured transaction * callbacks. An object with the following properties: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> * <dt>data (Object)</dt> <dd>Raw data.</dd> * Sends data as a normalized response to callback. * @param e {Event.Facade} Event Facade with the following properties: * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd> * <dt>request (Object)</dt> <dd>The request.</dd> * <dt>callback (Object)</dt> <dd>Deprecated alias for the * <strong>on</strong> property</dd> * <dt>on (Object)</dt> <dd>The map of configured transaction * callbacks. An object with the following properties: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> * <dt>data (Object)</dt> <dd>Raw data.</dd> * <dt>response (Object)</dt> <dd>Normalized response object with the following properties: * <dt>results (Object)</dt> <dd>Parsed results.</dd> * <dt>meta (Object)</dt> <dd>Parsed meta data.</dd> * <dt>error (Boolean)</dt> <dd>Error flag.</dd> // Send the response back to the callback * Generates a unique transaction ID and fires <code>request</code> event. * <strong>Note</strong>: the property <code>callback</code> is a * deprecated alias for the <code>on</code> transaction configuration * property described below. * @param request {Object} An object literal with the following properties: * <dt><code>request</code></dt> * <dd>The request to send to the live data source, if any.</dd> * <dt><code>on</code></dt> * <dd>An object literal with the following properties: * <dt><code>success</code></dt> * <dd>The function to call when the data is ready.</dd> * <dt><code>failure</code></dt> * <dd>The function to call upon a response failure condition.</dd> * <dt><code>argument</code></dt> * <dd>Arbitrary data payload that will be passed back to the success and failure handlers.</dd> * <dt><code>cfg</code></dt> * <dd>Configuration object, if any.</dd> * @return {Number} Transaction ID.