# Yahoo! UI Library

### datasource 3.0.0b1

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

## Class DataSource.Local - extends Base

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

Base class for the DataSource Utility.

### Constructor

DataSource.Local `( )`

### Properties

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

Global transaction counter.
Default Value: 0

#### NAME - `static final String`

Class name.

#### 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.

Returns: `void`

#### _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.

Returns: `void`

#### _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.

Returns: `void`

#### _initEvents

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

Returns: `void`

#### DataSource.issueCallback

`static void DataSource.issueCallback ( callback , params , error )`
Executes a given callback. The third param determines whether to execute

Parameters:
  `callback <Object>` The callback object.
  `params <Array>` params to be passed to the callback method
  `error <Boolean>` whether an error occurred

Returns: `void`

#### initializer

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

Parameters:
  `config <Object>` Config object.

Returns: `void`

#### sendRequest

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

Parameters:
  `request <Object>` Request.
  `callback <Object>` 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 <Object>` Configuration object

Returns: `Number`
  Transaction ID.

#### Methods inherited from EventTarget:

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

#### Methods inherited from Attribute:

`_addAttrs, _addLazyAttr, _defAttrChangeFn, _fireAttrChange, _getAttrInitVal, _isLazyAttr, _set, _setAttr, _setAttrVal, _splitAttrVals, addAttr, addAttrs, attrAdded, get, getAttrs, modifyAttr, removeAttr, reset, set, setAttrs`

#### Methods inherited from Plugin.Host:

`_destroyPlugins, _initPlugins, _plug, _unplug, hasPlugin, plug, unplug`

#### Methods inherited from Base:

`_aggregateAttrs, _defDestroyFn, _defInitFn, _destroyHierarchy, _filterAttrCfs, _getAttrCfgs, _getClasses, _initHierarchy, _initHierarchyData, 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 © 2009 Yahoo! Inc. All rights reserved.