forked from ReDEnergy/SessionSync
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneral.js
More file actions
53 lines (45 loc) · 1.11 KB
/
Copy pathgeneral.js
File metadata and controls
53 lines (45 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
define(function(require, exports) {
'use strict';
function copyProperties(source, destination) {
for (var prop in source) {
if (source.hasOwnProperty(prop)) {
destination[prop] = source[prop];
}
}
}
// Test if object is a valid javascript function
// Returns the same object if true or a new function otherwise
function getValidFunction(object)
{
var value = (typeof object === 'function' ? object : function () {});
return value;
}
function LimitCounter(limit, callback)
{
var func = getValidFunction(callback);
var counted = 0;
var triggered = false;
function checkLimit() {
if (!triggered && counted >= limit)
{
triggered = true;
func();
}
}
this.advance = function advance() {
counted++;
checkLimit();
}.bind(this);
this.offsetLimit = function offsetLimit(offset) {
limit += offset;
if (limit > 0) {
checkLimit();
}
};
}
// ------------------------------------------------------------------------
// Public API
exports.LimitCounter = LimitCounter;
exports.copyProperties = copyProperties;
exports.getValidFunction = getValidFunction;
});