# Yahoo! UI Library

### datasource 3.3.0

Yahoo! UI Library > datasource > DataSource.Local
Search:
Filters Show Private Show Protected Show Deprecated

## Class DataSource.Local - extends Base

Known Subclasses:
  Pollable DataSource.Get DataSource.IO DataSource.Function

Base class for the DataSource Utility.

### Constructor

DataSource.Local `( )`

### Properties

#### DataSource._tId - `private static Number`

Global transaction counter.
Default Value: 0

#### DataSource.transactions - `static Object`

Global in-progress transaction objects.

#### NAME - `static final String`

Class name.

#### Properties inherited from Plugin.Host:

`PluginHost`

#### Properties inherited from Attribute:

``

#### Properties inherited from Base:

`name`

### Methods

#### _defDataFn

`protected void _defDataFn ( e )`
Normalizes raw data into a response that includes results and meta properties.

Parameters:
  `e <Event.Facade>` Event Facade with the following properties:
  tId (Number)
    Unique transaction ID.
  request (Object)
    The request.
  callback (Object)
    The callback object with the following properties:
    success (Function)
      Success handler.
    failure (Function)
      Failure handler.
  cfg (Object)
    Configuration object.
  data (Object)
    Raw data.

#### _defRequestFn

`protected void _defRequestFn ( e )`
Manages request/response transaction. Must fire `response` event when response is received. This method should be implemented by subclasses to achieve more complex behavior such as accessing remote data.

Parameters:
  `e <Event.Facade>` Event Facadewith the following properties:
  tId (Number)
    Unique transaction ID.
  request (Object)
    The request.
  callback (Object)
    The callback object with the following properties:
    success (Function)
      Success handler.
    failure (Function)
      Failure handler.
  cfg (Object)
    Configuration object.

#### _defResponseFn

`protected void _defResponseFn ( e )`
Sends data as a normalized response to callback.

Parameters:
  `e <Event.Facade>` Event Facade with the following properties:
  tId (Number)
    Unique transaction ID.
  request (Object)
    The request.
  callback (Object)
    The callback object with the following properties:
    success (Function)
      Success handler.
    failure (Function)
      Failure handler.
  cfg (Object)
    Configuration object.
  data (Object)
    Raw data.
  response (Object)
    Normalized response object with the following properties:
    results (Object)
      Parsed results.
    meta (Object)
      Parsed meta data.
    error (Boolean)
      Error flag.

#### _initEvents

`private void _initEvents ( )`
This method creates all the events for this module.

#### DataSource.issueCallback

`static void DataSource.issueCallback ( e , caller )`
Returns data to callback.

Parameters:
  `e <EventFacade>` Event Facade.
  `caller <DataSource>` Calling DataSource instance.

#### initializer

`private void initializer ( config )`
Internal init() handler.

Parameters:
  `config <Object>` Config object.

#### sendRequest

`Number sendRequest ( request )`
Generates a unique transaction ID and fires `request` event.

Parameters:
  `request <Object>` An object literal with the following properties:
  `request`
    The request to send to the live data source, if any.
  `callback`
    An object literal with the following properties:
    `success`
      The function to call when the data is ready.
    `failure`
      The function to call upon a response failure condition.
    `argument`
      Arbitrary data payload that will be passed back to the success and failure handlers.
  `cfg`
    Configuration object, if any.

Returns: `Number`
  Transaction ID.

#### Methods inherited from EventTarget:

`_getType, _monitor, _parseType, addTarget, after, before, bubble, detach, detachAll, fire, getEvent, getTargets, on, once, parseType, publish, removeTarget, subscribe, unsubscribe, unsubscribeAll`

#### Methods inherited from Attribute:

`_addAttrs, _addLazyAttr, _defAttrChangeFn, _fireAttrChange, _getAttr, _getAttrCfg, _getAttrInitVal, _getAttrs, _getStateVal, _isLazyAttr, _normAttrVals, _protectAttrs, _set, _setAttr, _setAttrs, _setAttrVal, _setStateVal, addAttr, addAttrs, attrAdded, get, getAttrs, modifyAttr, removeAttr, reset, set, setAttrs`

#### Methods inherited from Plugin.Host:

`_destroyPlugins, _initPlugins, hasPlugin, plug, unplug`

#### Methods inherited from Base:

`_aggregateAttrs, _defDestroyFn, _defInitFn, _destroyHierarchy, _filterAttrCfs, _getAttrCfgs, _getClasses, _initHierarchy, _initHierarchyData, _preInitEventCfg, destroy, init, toString`

### Events

#### data

`data ( e )`
Fired when raw data is received.

Parameters:
  `e <Event.Facade>` Event Facade with the following properties:
  tId (Number)
    Unique transaction ID.
  request (Object)
    The request.
  callback (Object)
    The callback object with the following properties:
    success (Function)
      Success handler.
    failure (Function)
      Failure handler.
  cfg (Object)
    Configuration object.
  data (Object)
    Raw data.

Preventable: This event is preventable by method e.preventDefault(). The default function executed by this event is _defDataFn.

#### error

`error ( e )`
Fired when an error is encountered.

Parameters:
  `e <Event.Facade>` Event Facade with the following properties:
  tId (Number)
    Unique transaction ID.
  request (Object)
    The request.
  callback (Object)
    The callback object with the following properties:
    success (Function)
      Success handler.
    failure (Function)
      Failure handler.
  cfg (Object)
    Configuration object.
  data (Object)
    Raw data.
  response (Object)
    Normalized response object with the following properties:
    results (Object)
      Parsed results.
    meta (Object)
      Parsed meta data.
    error (Object)
      Error object.

#### request

`request ( e )`
Fired when a data request is received.

Parameters:
  `e <Event.Facade>` Event Facade with the following properties:
  tId (Number)
    Unique transaction ID.
  request (Object)
    The request.
  callback (Object)
    The callback object.
  cfg (Object)
    Configuration object.

Preventable: This event is preventable by method e.preventDefault(). The default function executed by this event is _defRequestFn.

#### response

`response ( e )`
Fired when response is returned.

Parameters:
  `e <Event.Facade>` Event Facade with the following properties:
  tId (Number)
    Unique transaction ID.
  request (Object)
    The request.
  callback (Object)
    The callback object with the following properties:
    success (Function)
      Success handler.
    failure (Function)
      Failure handler.
  cfg (Object)
    Configuration object.
  data (Object)
    Raw data.
  response (Object)
    Normalized response object with the following properties:
    results (Object)
      Parsed results.
    meta (Object)
      Parsed meta data.
    error (Boolean)
      Error flag.

Preventable: This event is preventable by method e.preventDefault(). The default function executed by this event is _defResponseFn.

#### sourceChange

`sourceChange ( event )`
Fires when the value for the configuration attribute 'source' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.

Parameters:
  `event <Event.Facade>` An Event Facade object with the following attribute specific properties added:
  prevVal
    The value of the attribute, prior to it being set
  newVal
    The value the attribute is to be set to
  attrName
    The name of the attribute being set
  subAttrName
    If setting a property within the attribute's value, the name of the sub-attribute property being set

#### Events inherited from Base:

`destroy, destroyedChange, init, initializedChange,`

### Configuration Attributes

#### source `- MIXED`

Pointer to live data.
Default Value: null

#### Configuration attributes inherited from Base:

`destroyed initialized`

Copyright © 2011 Yahoo! Inc. All rights reserved.