~launchpad-pqm/lazr-js/toolchain

« back to all changes in this revision

Viewing changes to src-js/lazrjs/yui/datasource/datasource-function-debug.js

  • Committer: Sidnei da Silva
  • Date: 2009-11-16 00:51:29 UTC
  • mto: This revision was merged to the branch mainline in revision 154.
  • Revision ID: sidnei.da.silva@canonical.com-20091116005129-8ibwjlboa38glaw5
- Improved generation of skin modules and revamped combo service to make it more twisty.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3
 
Code licensed under the BSD License:
4
 
http://developer.yahoo.com/yui/license.html
5
 
version: 3.2.0
6
 
build: 2676
7
 
*/
8
 
YUI.add('datasource-function', function(Y) {
9
 
 
10
 
/**
11
 
 * Provides a DataSource implementation which can be used to retrieve data from a custom function.
12
 
 *
13
 
 * @module datasource
14
 
 * @submodule datasource-function
15
 
 */
16
 
 
17
 
/**
18
 
 * Function subclass for the DataSource Utility.
19
 
 * @class DataSource.Function
20
 
 * @extends DataSource.Local
21
 
 * @constructor
22
 
 */    
23
 
var LANG = Y.Lang,
24
 
 
25
 
    DSFn = function() {
26
 
        DSFn.superclass.constructor.apply(this, arguments);
27
 
    };
28
 
    
29
 
 
30
 
    /////////////////////////////////////////////////////////////////////////////
31
 
    //
32
 
    // DataSource.Function static properties
33
 
    //
34
 
    /////////////////////////////////////////////////////////////////////////////
35
 
Y.mix(DSFn, {
36
 
    /**
37
 
     * Class name.
38
 
     *
39
 
     * @property NAME
40
 
     * @type String
41
 
     * @static     
42
 
     * @final
43
 
     * @value "dataSourceFunction"
44
 
     */
45
 
    NAME: "dataSourceFunction",
46
 
 
47
 
 
48
 
    /////////////////////////////////////////////////////////////////////////////
49
 
    //
50
 
    // DataSource.Function Attributes
51
 
    //
52
 
    /////////////////////////////////////////////////////////////////////////////
53
 
 
54
 
    ATTRS: {
55
 
        /**
56
 
        * @attribute source
57
 
        * @description Pointer to live data.
58
 
        * @type MIXED
59
 
        * @default null
60
 
        */
61
 
        source: {
62
 
            validator: LANG.isFunction
63
 
        }
64
 
    }
65
 
});
66
 
    
67
 
Y.extend(DSFn, Y.DataSource.Local, {
68
 
    /**
69
 
     * Passes query string to IO. Fires <code>response</code> event when
70
 
     * response is received asynchronously.
71
 
     *
72
 
     * @method _defRequestFn
73
 
     * @param e {Event.Facade} Event Facade with the following properties:
74
 
     * <dl>
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:
78
 
     *     <dl>
79
 
     *         <dt>success (Function)</dt> <dd>Success handler.</dd>
80
 
     *         <dt>failure (Function)</dt> <dd>Failure handler.</dd>
81
 
     *     </dl>
82
 
     * </dd>
83
 
     * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
84
 
     * </dl>
85
 
     * @protected
86
 
     */
87
 
    _defRequestFn: function(e) {
88
 
        var fn = this.get("source"),
89
 
            response;
90
 
            
91
 
            if(fn) {
92
 
                try {
93
 
                    response = fn(e.request, this, e);
94
 
                    this.fire("data", Y.mix({data:response}, e));
95
 
                }
96
 
                catch(error) {
97
 
                    e.error = error;
98
 
                    Y.log("Function execution failure", "error", "datasource-function");
99
 
                    this.fire("data", e);
100
 
                }
101
 
            }
102
 
            else {
103
 
                e.error = new Error("Function data failure");
104
 
                Y.log("Function data failure", "error", "datasource-function");
105
 
                this.fire("data", e);
106
 
            }
107
 
            
108
 
        return e.tId;
109
 
    }
110
 
});
111
 
  
112
 
Y.DataSource.Function = DSFn;
113
 
    
114
 
 
115
 
 
116
 
 
117
 
}, '3.2.0' ,{requires:['datasource-local']});