1 /** 2 * The Render Engine 3 * OneShotTrigger 4 * 5 * @fileoverview An single interval timer, with sub-intervals, which self-destroys. 6 * 7 * @author: Brett Fattori (brettf@renderengine.com) 8 * @author: $Author: bfattori $ 9 * @version: $Revision: 1555 $ 10 * 11 * Copyright (c) 2011 Brett Fattori (brettf@renderengine.com) 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining a copy 14 * of this software and associated documentation files (the "Software"), to deal 15 * in the Software without restriction, including without limitation the rights 16 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 * copies of the Software, and to permit persons to whom the Software is 18 * furnished to do so, subject to the following conditions: 19 * 20 * The above copyright notice and this permission notice shall be included in 21 * all copies or substantial portions of the Software. 22 * 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 * THE SOFTWARE. 30 * 31 */ 32 33 // The class this file defines and its required classes 34 R.Engine.define({ 35 "class":"R.lang.OneShotTrigger", 36 "requires":[ 37 "R.lang.OneShotTimeout" 38 ] 39 }); 40 41 /** 42 * @class An extension of {@link R.lang.OneShotTimeout} which is a one-shot timer that triggers a callback, 43 * at regular intervals, until the timer has expired. When the timer expires, the 44 * trigger will automatically destroy itself. Within the callbacks, <tt>this</tt> 45 * refers to the <tt>Timer</tt> object itself. 46 * 47 * @param name {String} The name of the timer 48 * @param interval {Number} The full interval for the timer, in milliseconds 49 * @param callback {Function} The function to call when the full interval is reached 50 * @param triggerInterval {Number} The interval between triggers, in milliseconds 51 * @param triggerCallback {Function} The function to call for each trigger interval 52 * @extends R.lang.OneShotTimeout 53 * @constructor 54 * @description Create a one-shot triggering timeout 55 */ 56 R.lang.OneShotTrigger = function () { 57 "use strict"; 58 return R.lang.OneShotTimeout.extend(/** @scope R.lang.OneShotTrigger.prototype */{ 59 60 constructor:function (name, interval, callback, triggerInterval, triggerCallback) { 61 var timerObj = { 62 interval:R.lang.IntervalTimer.create(name + "_trigger", triggerInterval, triggerCallback), 63 callback:callback, 64 timer:this 65 }; 66 67 var doneFn = R.bind(timerObj, function () { 68 this.interval.destroy(); 69 this.callback.call(this.timer); 70 }); 71 72 this.base(name, interval, doneFn); 73 } 74 }, /** @scope R.lang.OneShotTrigger.prototype */ { 75 76 /** 77 * Get the class name of this object 78 * @return {String} "R.lang.OneShotTrigger" 79 */ 80 getClassName:function () { 81 return "R.lang.OneShotTrigger"; 82 } 83 }); 84 85 }