[Core] Add newlines
Add newlines to scripts added to core for WTD-1202.
This commit is contained in:
@@ -4,7 +4,7 @@ define(
|
|||||||
[],
|
[],
|
||||||
function () {
|
function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throttler for function executions, registered as the `throttle`
|
* Throttler for function executions, registered as the `throttle`
|
||||||
* service.
|
* service.
|
||||||
@@ -13,7 +13,7 @@ define(
|
|||||||
*
|
*
|
||||||
* throttle(fn, delay, [apply])
|
* 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.
|
* `delay` milliseconds, only if no other invocations are pending.
|
||||||
* The optional argument `apply` determines whether.
|
* The optional argument `apply` determines whether.
|
||||||
*
|
*
|
||||||
@@ -28,36 +28,36 @@ define(
|
|||||||
* @param {Function} fn the function to throttle
|
* @param {Function} fn the function to throttle
|
||||||
* @param {number} [delay] the delay, in milliseconds, before
|
* @param {number} [delay] the delay, in milliseconds, before
|
||||||
* executing this function; defaults to 0.
|
* 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
|
* invoked after this function executes; defaults to
|
||||||
* `false`.
|
* `false`.
|
||||||
*/
|
*/
|
||||||
return function (fn, delay, apply) {
|
return function (fn, delay, apply) {
|
||||||
var activeTimeout;
|
var activeTimeout;
|
||||||
|
|
||||||
// Clear active timeout, so that next invocation starts
|
// Clear active timeout, so that next invocation starts
|
||||||
// a new one.
|
// a new one.
|
||||||
function clearActiveTimeout() {
|
function clearActiveTimeout() {
|
||||||
activeTimeout = undefined;
|
activeTimeout = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Defaults
|
// Defaults
|
||||||
delay = delay || 0;
|
delay = delay || 0;
|
||||||
apply = apply || false;
|
apply = apply || false;
|
||||||
|
|
||||||
return function () {
|
return function () {
|
||||||
// Start a timeout if needed
|
// Start a timeout if needed
|
||||||
if (!activeTimeout) {
|
if (!activeTimeout) {
|
||||||
activeTimeout = $timeout(fn, delay, apply);
|
activeTimeout = $timeout(fn, delay, apply);
|
||||||
activeTimeout.then(clearActiveTimeout);
|
activeTimeout.then(clearActiveTimeout);
|
||||||
}
|
}
|
||||||
// Return whichever timeout is active (to get
|
// Return whichever timeout is active (to get
|
||||||
// a promise for the results of fn)
|
// a promise for the results of fn)
|
||||||
return activeTimeout;
|
return activeTimeout;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return Throttle;
|
return Throttle;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ define(
|
|||||||
mockTimeout,
|
mockTimeout,
|
||||||
mockFn,
|
mockFn,
|
||||||
mockPromise;
|
mockPromise;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockTimeout = jasmine.createSpy("$timeout");
|
mockTimeout = jasmine.createSpy("$timeout");
|
||||||
mockPromise = jasmine.createSpyObj("promise", ["then"]);
|
mockPromise = jasmine.createSpyObj("promise", ["then"]);
|
||||||
@@ -18,7 +18,7 @@ define(
|
|||||||
mockTimeout.andReturn(mockPromise);
|
mockTimeout.andReturn(mockPromise);
|
||||||
throttle = new Throttle(mockTimeout);
|
throttle = new Throttle(mockTimeout);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("provides functions which run on a timeout", function () {
|
it("provides functions which run on a timeout", function () {
|
||||||
var throttled = throttle(mockFn);
|
var throttled = throttle(mockFn);
|
||||||
// Verify precondition: Not called at throttle-time
|
// Verify precondition: Not called at throttle-time
|
||||||
@@ -26,7 +26,7 @@ define(
|
|||||||
expect(throttled()).toEqual(mockPromise);
|
expect(throttled()).toEqual(mockPromise);
|
||||||
expect(mockTimeout).toHaveBeenCalledWith(mockFn, 0, false);
|
expect(mockTimeout).toHaveBeenCalledWith(mockFn, 0, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("schedules only one timeout at a time", function () {
|
it("schedules only one timeout at a time", function () {
|
||||||
var throttled = throttle(mockFn);
|
var throttled = throttle(mockFn);
|
||||||
throttled();
|
throttled();
|
||||||
@@ -34,7 +34,7 @@ define(
|
|||||||
throttled();
|
throttled();
|
||||||
expect(mockTimeout.calls.length).toEqual(1);
|
expect(mockTimeout.calls.length).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("schedules additional invocations after resolution", function () {
|
it("schedules additional invocations after resolution", function () {
|
||||||
var throttled = throttle(mockFn);
|
var throttled = throttle(mockFn);
|
||||||
throttled();
|
throttled();
|
||||||
@@ -46,4 +46,4 @@ define(
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user