[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 /* 2 YUI 3.17.2 (build 9c3c78e) 3 Copyright 2014 Yahoo! Inc. All rights reserved. 4 Licensed under the BSD License. 5 http://yuilibrary.com/license/ 6 */ 7 8 YUI.add('datasource-function', function (Y, NAME) { 9 10 /** 11 * Provides a DataSource implementation which can be used to retrieve data from 12 * a custom function. 13 * 14 * @module datasource 15 * @submodule datasource-function 16 */ 17 18 /** 19 * Function subclass for the DataSource Utility. 20 * @class DataSource.Function 21 * @extends DataSource.Local 22 * @constructor 23 */ 24 var LANG = Y.Lang, 25 26 DSFn = function() { 27 DSFn.superclass.constructor.apply(this, arguments); 28 }; 29 30 31 ///////////////////////////////////////////////////////////////////////////// 32 // 33 // DataSource.Function static properties 34 // 35 ///////////////////////////////////////////////////////////////////////////// 36 Y.mix(DSFn, { 37 /** 38 * Class name. 39 * 40 * @property NAME 41 * @type String 42 * @static 43 * @final 44 * @value "dataSourceFunction" 45 */ 46 NAME: "dataSourceFunction", 47 48 49 ///////////////////////////////////////////////////////////////////////////// 50 // 51 // DataSource.Function Attributes 52 // 53 ///////////////////////////////////////////////////////////////////////////// 54 55 ATTRS: { 56 /** 57 * Stores the function that will serve the response data. 58 * 59 * @attribute source 60 * @type {Any} 61 * @default null 62 */ 63 source: { 64 validator: LANG.isFunction 65 } 66 } 67 }); 68 69 Y.extend(DSFn, Y.DataSource.Local, { 70 /** 71 * Passes query data to the source function. Fires <code>response</code> 72 * event with the function results (synchronously). 73 * 74 * @method _defRequestFn 75 * @param e {EventFacade} Event Facade with the following properties: 76 * <dl> 77 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd> 78 * <dt>request (Object)</dt> <dd>The request.</dd> 79 * <dt>callback (Object)</dt> <dd>The callback object with the following 80 * properties: 81 * <dl> 82 * <dt>success (Function)</dt> <dd>Success handler.</dd> 83 * <dt>failure (Function)</dt> <dd>Failure handler.</dd> 84 * </dl> 85 * </dd> 86 * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> 87 * </dl> 88 * @protected 89 */ 90 _defRequestFn: function(e) { 91 var fn = this.get("source"), 92 payload = e.details[0]; 93 94 if (fn) { 95 try { 96 payload.data = fn(e.request, this, e); 97 } catch (ex) { 98 Y.log("Function execution failure", "error", "datasource-function"); 99 payload.error = ex; 100 } 101 } else { 102 Y.log("Function data failure", "error", "datasource-function"); 103 payload.error = new Error("Function data failure"); 104 } 105 106 this.fire("data", payload); 107 108 return e.tId; 109 } 110 }); 111 112 Y.DataSource.Function = DSFn; 113 114 115 }, '3.17.2', {"requires": ["datasource-local"]});
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |