2
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3
Code licensed under the BSD License:
4
http://developer.yahoo.com/yui/license.html
8
YUI.add('datasource-function', function(Y) {
11
* Provides a DataSource implementation which can be used to retrieve data from a custom function.
14
* @submodule datasource-function
18
* Function subclass for the DataSource Utility.
19
* @class DataSource.Function
20
* @extends DataSource.Local
26
DSFn.superclass.constructor.apply(this, arguments);
30
/////////////////////////////////////////////////////////////////////////////
32
// DataSource.Function static properties
34
/////////////////////////////////////////////////////////////////////////////
43
* @value "dataSourceFunction"
45
NAME: "dataSourceFunction",
48
/////////////////////////////////////////////////////////////////////////////
50
// DataSource.Function Attributes
52
/////////////////////////////////////////////////////////////////////////////
57
* @description Pointer to live data.
62
validator: LANG.isFunction
67
Y.extend(DSFn, Y.DataSource.Local, {
69
* Passes query string to IO. Fires <code>response</code> event when
70
* response is received asynchronously.
72
* @method _defRequestFn
73
* @param e {Event.Facade} Event Facade with the following properties:
75
* <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
76
* <dt>request (Object)</dt> <dd>The request.</dd>
77
* <dt>callback (Object)</dt> <dd>The callback object with the following properties:
79
* <dt>success (Function)</dt> <dd>Success handler.</dd>
80
* <dt>failure (Function)</dt> <dd>Failure handler.</dd>
83
* <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
87
_defRequestFn: function(e) {
88
var fn = this.get("source"),
93
response = fn(e.request, this, e);
94
this.fire("data", Y.mix({data:response}, e));
98
Y.log("Function execution failure", "error", "datasource-function");
103
e.error = new Error("Function data failure");
104
Y.log("Function data failure", "error", "datasource-function");
105
this.fire("data", e);
112
Y.DataSource.Function = DSFn;
117
}, '3.2.0' ,{requires:['datasource-local']});