diff --git a/platform/core/src/services/Throttle.js b/platform/core/src/services/Throttle.js index 619f53161e..0c86a403c7 100644 --- a/platform/core/src/services/Throttle.js +++ b/platform/core/src/services/Throttle.js @@ -4,7 +4,7 @@ define( [], function () { "use strict"; - + /** * Throttler for function executions, registered as the `throttle` * service. @@ -13,7 +13,7 @@ define( * * throttle(fn, delay, [apply]) * - * Returns a function that, when invoked, will invoke `fn` after + * Returns a function that, when invoked, will invoke `fn` after * `delay` milliseconds, only if no other invocations are pending. * The optional argument `apply` determines whether. * @@ -28,36 +28,36 @@ define( * @param {Function} fn the function to throttle * @param {number} [delay] the delay, in milliseconds, before * executing this function; defaults to 0. - * @param {boolean} apply true if a `$apply` call should be + * @param {boolean} apply true if a `$apply` call should be * invoked after this function executes; defaults to * `false`. */ return function (fn, delay, apply) { var activeTimeout; - + // Clear active timeout, so that next invocation starts // a new one. function clearActiveTimeout() { activeTimeout = undefined; } - + // Defaults delay = delay || 0; apply = apply || false; - + return function () { // Start a timeout if needed if (!activeTimeout) { activeTimeout = $timeout(fn, delay, apply); activeTimeout.then(clearActiveTimeout); } - // Return whichever timeout is active (to get + // Return whichever timeout is active (to get // a promise for the results of fn) return activeTimeout; }; }; } - + return Throttle; } -); \ No newline at end of file +); diff --git a/platform/core/test/services/ThrottleSpec.js b/platform/core/test/services/ThrottleSpec.js index ccd6644eb7..173fad8006 100644 --- a/platform/core/test/services/ThrottleSpec.js +++ b/platform/core/test/services/ThrottleSpec.js @@ -10,7 +10,7 @@ define( mockTimeout, mockFn, mockPromise; - + beforeEach(function () { mockTimeout = jasmine.createSpy("$timeout"); mockPromise = jasmine.createSpyObj("promise", ["then"]); @@ -18,7 +18,7 @@ define( mockTimeout.andReturn(mockPromise); throttle = new Throttle(mockTimeout); }); - + it("provides functions which run on a timeout", function () { var throttled = throttle(mockFn); // Verify precondition: Not called at throttle-time @@ -26,7 +26,7 @@ define( expect(throttled()).toEqual(mockPromise); expect(mockTimeout).toHaveBeenCalledWith(mockFn, 0, false); }); - + it("schedules only one timeout at a time", function () { var throttled = throttle(mockFn); throttled(); @@ -34,7 +34,7 @@ define( throttled(); expect(mockTimeout.calls.length).toEqual(1); }); - + it("schedules additional invocations after resolution", function () { var throttled = throttle(mockFn); throttled(); @@ -46,4 +46,4 @@ define( }); }); } -); \ No newline at end of file +);