-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathember-runtime.js
More file actions
21941 lines (18484 loc) · 661 KB
/
ember-runtime.js
File metadata and controls
21941 lines (18484 loc) · 661 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;(function() {
/*!
* @overview Ember - JavaScript Application Framework
* @copyright Copyright 2011-2016 Tilde Inc. and contributors
* Portions Copyright 2006-2011 Strobe Inc.
* Portions Copyright 2008-2011 Apple Inc. All rights reserved.
* @license Licensed under MIT license
* See https://raw.github.com/emberjs/ember.js/master/LICENSE
* @version 2.11.0-beta.4
*/
var enifed, requireModule, Ember;
(function() {
var isNode = typeof window === 'undefined' &&
typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
if (!isNode) {
Ember = this.Ember = this.Ember || {};
}
if (typeof Ember === 'undefined') { Ember = {}; }
if (typeof Ember.__loader === 'undefined') {
var registry = {};
var seen = {};
enifed = function(name, deps, callback) {
var value = { };
if (!callback) {
value.deps = [];
value.callback = deps;
} else {
value.deps = deps;
value.callback = callback;
}
registry[name] = value;
};
requireModule = function(name) {
return internalRequire(name, null);
};
// setup `require` module
requireModule['default'] = requireModule;
requireModule.has = function registryHas(moduleName) {
return !!registry[moduleName] || !!registry[moduleName + '/index'];
};
function missingModule(name, referrerName) {
if (referrerName) {
throw new Error('Could not find module ' + name + ' required by: ' + referrerName);
} else {
throw new Error('Could not find module ' + name);
}
}
function internalRequire(_name, referrerName) {
var name = _name;
var mod = registry[name];
if (!mod) {
name = name + '/index';
mod = registry[name];
}
var exports = seen[name];
if (exports !== undefined) {
return exports;
}
exports = seen[name] = {};
if (!mod) {
missingModule(_name, referrerName);
}
var deps = mod.deps;
var callback = mod.callback;
var reified = new Array(deps.length);
for (var i = 0; i < deps.length; i++) {
if (deps[i] === 'exports') {
reified[i] = exports;
} else if (deps[i] === 'require') {
reified[i] = requireModule;
} else {
reified[i] = internalRequire(deps[i], name);
}
}
callback.apply(this, reified);
return exports;
}
requireModule._eak_seen = registry;
Ember.__loader = {
define: enifed,
require: requireModule,
registry: registry
};
} else {
enifed = Ember.__loader.define;
requireModule = Ember.__loader.require;
}
})();
function inherits(subClass, superClass) {
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : defaults(subClass, superClass);
}
function taggedTemplateLiteralLoose(strings, raw) {
strings.raw = raw;
return strings;
}
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ('value' in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function createClass(Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
}
function interopExportWildcard(obj, defaults) {
var newObj = defaults({}, obj);
delete newObj['default'];
return newObj;
}
function defaults(obj, defaults) {
var keys = Object.getOwnPropertyNames(defaults);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var value = Object.getOwnPropertyDescriptor(defaults, key);
if (value && value.configurable && obj[key] === undefined) {
Object.defineProperty(obj, key, value);
}
}
return obj;
}
babelHelpers = {
inherits: inherits,
taggedTemplateLiteralLoose: taggedTemplateLiteralLoose,
slice: Array.prototype.slice,
createClass: createClass,
interopExportWildcard: interopExportWildcard,
defaults: defaults
};
enifed('backburner', ['exports'], function (exports) { 'use strict';
var NUMBER = /\d+/;
function each(collection, callback) {
for (var i = 0; i < collection.length; i++) {
callback(collection[i]);
}
}
function isString(suspect) {
return typeof suspect === 'string';
}
function isFunction(suspect) {
return typeof suspect === 'function';
}
function isNumber(suspect) {
return typeof suspect === 'number';
}
function isCoercableNumber(number) {
return isNumber(number) || NUMBER.test(number);
}
function binarySearch(time, timers) {
var start = 0;
var end = timers.length - 2;
var middle, l;
while (start < end) {
// since timers is an array of pairs 'l' will always
// be an integer
l = (end - start) / 2;
// compensate for the index in case even number
// of pairs inside timers
middle = start + l - (l % 2);
if (time >= timers[middle]) {
start = middle + 2;
} else {
end = middle;
}
}
return (time >= timers[start]) ? start + 2 : start;
}
function Queue(name, options, globalOptions) {
this.name = name;
this.globalOptions = globalOptions || {};
this.options = options;
this._queue = [];
this.targetQueues = {};
this._queueBeingFlushed = undefined;
}
Queue.prototype = {
push: function(target, method, args, stack) {
var queue = this._queue;
queue.push(target, method, args, stack);
return {
queue: this,
target: target,
method: method
};
},
pushUniqueWithoutGuid: function(target, method, args, stack) {
var queue = this._queue;
for (var i = 0, l = queue.length; i < l; i += 4) {
var currentTarget = queue[i];
var currentMethod = queue[i+1];
if (currentTarget === target && currentMethod === method) {
queue[i+2] = args; // replace args
queue[i+3] = stack; // replace stack
return;
}
}
queue.push(target, method, args, stack);
},
targetQueue: function(targetQueue, target, method, args, stack) {
var queue = this._queue;
for (var i = 0, l = targetQueue.length; i < l; i += 2) {
var currentMethod = targetQueue[i];
var currentIndex = targetQueue[i + 1];
if (currentMethod === method) {
queue[currentIndex + 2] = args; // replace args
queue[currentIndex + 3] = stack; // replace stack
return;
}
}
targetQueue.push(
method,
queue.push(target, method, args, stack) - 4
);
},
pushUniqueWithGuid: function(guid, target, method, args, stack) {
var hasLocalQueue = this.targetQueues[guid];
if (hasLocalQueue) {
this.targetQueue(hasLocalQueue, target, method, args, stack);
} else {
this.targetQueues[guid] = [
method,
this._queue.push(target, method, args, stack) - 4
];
}
return {
queue: this,
target: target,
method: method
};
},
pushUnique: function(target, method, args, stack) {
var KEY = this.globalOptions.GUID_KEY;
if (target && KEY) {
var guid = target[KEY];
if (guid) {
return this.pushUniqueWithGuid(guid, target, method, args, stack);
}
}
this.pushUniqueWithoutGuid(target, method, args, stack);
return {
queue: this,
target: target,
method: method
};
},
invoke: function(target, method, args /*, onError, errorRecordedForStack */) {
if (args && args.length > 0) {
method.apply(target, args);
} else {
method.call(target);
}
},
invokeWithOnError: function(target, method, args, onError, errorRecordedForStack) {
try {
if (args && args.length > 0) {
method.apply(target, args);
} else {
method.call(target);
}
} catch(error) {
onError(error, errorRecordedForStack);
}
},
flush: function(sync) {
var queue = this._queue;
var length = queue.length;
if (length === 0) {
return;
}
var globalOptions = this.globalOptions;
var options = this.options;
var before = options && options.before;
var after = options && options.after;
var onError = globalOptions.onError || (globalOptions.onErrorTarget &&
globalOptions.onErrorTarget[globalOptions.onErrorMethod]);
var target, method, args, errorRecordedForStack;
var invoke = onError ? this.invokeWithOnError : this.invoke;
this.targetQueues = Object.create(null);
var queueItems = this._queueBeingFlushed = this._queue.slice();
this._queue = [];
if (before) {
before();
}
for (var i = 0; i < length; i += 4) {
target = queueItems[i];
method = queueItems[i+1];
args = queueItems[i+2];
errorRecordedForStack = queueItems[i+3]; // Debugging assistance
if (isString(method)) {
method = target[method];
}
// method could have been nullified / canceled during flush
if (method) {
//
// ** Attention intrepid developer **
//
// To find out the stack of this task when it was scheduled onto
// the run loop, add the following to your app.js:
//
// Ember.run.backburner.DEBUG = true; // NOTE: This slows your app, don't leave it on in production.
//
// Once that is in place, when you are at a breakpoint and navigate
// here in the stack explorer, you can look at `errorRecordedForStack.stack`,
// which will be the captured stack when this job was scheduled.
//
// One possible long-term solution is the following Chrome issue:
// https://bugs.chromium.org/p/chromium/issues/detail?id=332624
//
invoke(target, method, args, onError, errorRecordedForStack);
}
}
if (after) {
after();
}
this._queueBeingFlushed = undefined;
if (sync !== false &&
this._queue.length > 0) {
// check if new items have been added
this.flush(true);
}
},
cancel: function(actionToCancel) {
var queue = this._queue, currentTarget, currentMethod, i, l;
var target = actionToCancel.target;
var method = actionToCancel.method;
var GUID_KEY = this.globalOptions.GUID_KEY;
if (GUID_KEY && this.targetQueues && target) {
var targetQueue = this.targetQueues[target[GUID_KEY]];
if (targetQueue) {
for (i = 0, l = targetQueue.length; i < l; i++) {
if (targetQueue[i] === method) {
targetQueue.splice(i, 1);
}
}
}
}
for (i = 0, l = queue.length; i < l; i += 4) {
currentTarget = queue[i];
currentMethod = queue[i+1];
if (currentTarget === target &&
currentMethod === method) {
queue.splice(i, 4);
return true;
}
}
// if not found in current queue
// could be in the queue that is being flushed
queue = this._queueBeingFlushed;
if (!queue) {
return;
}
for (i = 0, l = queue.length; i < l; i += 4) {
currentTarget = queue[i];
currentMethod = queue[i+1];
if (currentTarget === target &&
currentMethod === method) {
// don't mess with array during flush
// just nullify the method
queue[i+1] = null;
return true;
}
}
}
};
function DeferredActionQueues(queueNames, options) {
var queues = this.queues = {};
this.queueNames = queueNames = queueNames || [];
this.options = options;
each(queueNames, function(queueName) {
queues[queueName] = new Queue(queueName, options[queueName], options);
});
}
function noSuchQueue(name) {
throw new Error('You attempted to schedule an action in a queue (' + name + ') that doesn\'t exist');
}
function noSuchMethod(name) {
throw new Error('You attempted to schedule an action in a queue (' + name + ') for a method that doesn\'t exist');
}
DeferredActionQueues.prototype = {
schedule: function(name, target, method, args, onceFlag, stack) {
var queues = this.queues;
var queue = queues[name];
if (!queue) {
noSuchQueue(name);
}
if (!method) {
noSuchMethod(name);
}
if (onceFlag) {
return queue.pushUnique(target, method, args, stack);
} else {
return queue.push(target, method, args, stack);
}
},
flush: function() {
var queues = this.queues;
var queueNames = this.queueNames;
var queueName, queue;
var queueNameIndex = 0;
var numberOfQueues = queueNames.length;
while (queueNameIndex < numberOfQueues) {
queueName = queueNames[queueNameIndex];
queue = queues[queueName];
var numberOfQueueItems = queue._queue.length;
if (numberOfQueueItems === 0) {
queueNameIndex++;
} else {
queue.flush(false /* async */);
queueNameIndex = 0;
}
}
}
};
function Backburner(queueNames, options) {
this.queueNames = queueNames;
this.options = options || {};
if (!this.options.defaultQueue) {
this.options.defaultQueue = queueNames[0];
}
this.instanceStack = [];
this._debouncees = [];
this._throttlers = [];
this._eventCallbacks = {
end: [],
begin: []
};
var _this = this;
this._boundClearItems = function() {
clearItems();
};
this._timerTimeoutId = undefined;
this._timers = [];
this._platform = this.options._platform || {
setTimeout: function (fn, ms) {
return setTimeout(fn, ms);
},
clearTimeout: function (id) {
clearTimeout(id);
}
};
this._boundRunExpiredTimers = function () {
_this._runExpiredTimers();
};
}
Backburner.prototype = {
begin: function() {
var options = this.options;
var onBegin = options && options.onBegin;
var previousInstance = this.currentInstance;
if (previousInstance) {
this.instanceStack.push(previousInstance);
}
this.currentInstance = new DeferredActionQueues(this.queueNames, options);
this._trigger('begin', this.currentInstance, previousInstance);
if (onBegin) {
onBegin(this.currentInstance, previousInstance);
}
},
end: function() {
var options = this.options;
var onEnd = options && options.onEnd;
var currentInstance = this.currentInstance;
var nextInstance = null;
// Prevent double-finally bug in Safari 6.0.2 and iOS 6
// This bug appears to be resolved in Safari 6.0.5 and iOS 7
var finallyAlreadyCalled = false;
try {
currentInstance.flush();
} finally {
if (!finallyAlreadyCalled) {
finallyAlreadyCalled = true;
this.currentInstance = null;
if (this.instanceStack.length) {
nextInstance = this.instanceStack.pop();
this.currentInstance = nextInstance;
}
this._trigger('end', currentInstance, nextInstance);
if (onEnd) {
onEnd(currentInstance, nextInstance);
}
}
}
},
/**
Trigger an event. Supports up to two arguments. Designed around
triggering transition events from one run loop instance to the
next, which requires an argument for the first instance and then
an argument for the next instance.
@private
@method _trigger
@param {String} eventName
@param {any} arg1
@param {any} arg2
*/
_trigger: function(eventName, arg1, arg2) {
var callbacks = this._eventCallbacks[eventName];
if (callbacks) {
for (var i = 0; i < callbacks.length; i++) {
callbacks[i](arg1, arg2);
}
}
},
on: function(eventName, callback) {
if (typeof callback !== 'function') {
throw new TypeError('Callback must be a function');
}
var callbacks = this._eventCallbacks[eventName];
if (callbacks) {
callbacks.push(callback);
} else {
throw new TypeError('Cannot on() event "' + eventName + '" because it does not exist');
}
},
off: function(eventName, callback) {
if (eventName) {
var callbacks = this._eventCallbacks[eventName];
var callbackFound = false;
if (!callbacks) return;
if (callback) {
for (var i = 0; i < callbacks.length; i++) {
if (callbacks[i] === callback) {
callbackFound = true;
callbacks.splice(i, 1);
i--;
}
}
}
if (!callbackFound) {
throw new TypeError('Cannot off() callback that does not exist');
}
} else {
throw new TypeError('Cannot off() event "' + eventName + '" because it does not exist');
}
},
run: function(/* target, method, args */) {
var length = arguments.length;
var method, target, args;
if (length === 1) {
method = arguments[0];
target = null;
} else {
target = arguments[0];
method = arguments[1];
}
if (isString(method)) {
method = target[method];
}
if (length > 2) {
args = new Array(length - 2);
for (var i = 0, l = length - 2; i < l; i++) {
args[i] = arguments[i + 2];
}
} else {
args = [];
}
var onError = getOnError(this.options);
this.begin();
// guard against Safari 6's double-finally bug
var didFinally = false;
if (onError) {
try {
return method.apply(target, args);
} catch(error) {
onError(error);
} finally {
if (!didFinally) {
didFinally = true;
this.end();
}
}
} else {
try {
return method.apply(target, args);
} finally {
if (!didFinally) {
didFinally = true;
this.end();
}
}
}
},
/*
Join the passed method with an existing queue and execute immediately,
if there isn't one use `Backburner#run`.
The join method is like the run method except that it will schedule into
an existing queue if one already exists. In either case, the join method will
immediately execute the passed in function and return its result.
@method join
@param {Object} target
@param {Function} method The method to be executed
@param {any} args The method arguments
@return method result
*/
join: function(/* target, method, args */) {
if (!this.currentInstance) {
return this.run.apply(this, arguments);
}
var length = arguments.length;
var method, target;
if (length === 1) {
method = arguments[0];
target = null;
} else {
target = arguments[0];
method = arguments[1];
}
if (isString(method)) {
method = target[method];
}
if (length === 1) {
return method();
} else if (length === 2) {
return method.call(target);
} else {
var args = new Array(length - 2);
for (var i = 0, l = length - 2; i < l; i++) {
args[i] = arguments[i + 2];
}
return method.apply(target, args);
}
},
/*
Defer the passed function to run inside the specified queue.
@method defer
@param {String} queueName
@param {Object} target
@param {Function|String} method The method or method name to be executed
@param {any} args The method arguments
@return method result
*/
defer: function(queueName /* , target, method, args */) {
var length = arguments.length;
var method, target, args;
if (length === 2) {
method = arguments[1];
target = null;
} else {
target = arguments[1];
method = arguments[2];
}
if (isString(method)) {
method = target[method];
}
var stack = this.DEBUG ? new Error() : undefined;
if (length > 3) {
args = new Array(length - 3);
for (var i = 3; i < length; i++) {
args[i-3] = arguments[i];
}
} else {
args = undefined;
}
if (!this.currentInstance) { createAutorun(this); }
return this.currentInstance.schedule(queueName, target, method, args, false, stack);
},
deferOnce: function(queueName /* , target, method, args */) {
var length = arguments.length;
var method, target, args;
if (length === 2) {
method = arguments[1];
target = null;
} else {
target = arguments[1];
method = arguments[2];
}
if (isString(method)) {
method = target[method];
}
var stack = this.DEBUG ? new Error() : undefined;
if (length > 3) {
args = new Array(length - 3);
for (var i = 3; i < length; i++) {
args[i-3] = arguments[i];
}
} else {
args = undefined;
}
if (!this.currentInstance) {
createAutorun(this);
}
return this.currentInstance.schedule(queueName, target, method, args, true, stack);
},
setTimeout: function() {
var l = arguments.length;
var args = new Array(l);
for (var x = 0; x < l; x++) {
args[x] = arguments[x];
}
var length = args.length,
method, wait, target,
methodOrTarget, methodOrWait, methodOrArgs;
if (length === 0) {
return;
} else if (length === 1) {
method = args.shift();
wait = 0;
} else if (length === 2) {
methodOrTarget = args[0];
methodOrWait = args[1];
if (isFunction(methodOrWait) || isFunction(methodOrTarget[methodOrWait])) {
target = args.shift();
method = args.shift();
wait = 0;
} else if (isCoercableNumber(methodOrWait)) {
method = args.shift();
wait = args.shift();
} else {
method = args.shift();
wait = 0;
}
} else {
var last = args[args.length - 1];
if (isCoercableNumber(last)) {
wait = args.pop();
} else {
wait = 0;
}
methodOrTarget = args[0];
methodOrArgs = args[1];
if (isFunction(methodOrArgs) || (isString(methodOrArgs) &&
methodOrTarget !== null &&
methodOrArgs in methodOrTarget)) {
target = args.shift();
method = args.shift();
} else {
method = args.shift();
}
}
var executeAt = Date.now() + parseInt(wait !== wait ? 0 : wait, 10);
if (isString(method)) {
method = target[method];
}
var onError = getOnError(this.options);
function fn() {
if (onError) {
try {
method.apply(target, args);
} catch (e) {
onError(e);
}
} else {
method.apply(target, args);
}
}
return this._setTimeout(fn, executeAt);
},
_setTimeout: function (fn, executeAt) {
if (this._timers.length === 0) {
this._timers.push(executeAt, fn);
this._installTimerTimeout();
return fn;
}
// find position to insert
var i = binarySearch(executeAt, this._timers);
this._timers.splice(i, 0, executeAt, fn);
// we should be the new earliest timer if i == 0
if (i === 0) {
this._reinstallTimerTimeout();
}
return fn;
},
throttle: function(target, method /* , args, wait, [immediate] */) {
var backburner = this;
var args = new Array(arguments.length);
for (var i = 0; i < arguments.length; i++) {
args[i] = arguments[i];
}
var immediate = args.pop();
var wait, throttler, index, timer;
if (isNumber(immediate) || isString(immediate)) {
wait = immediate;
immediate = true;
} else {
wait = args.pop();
}
wait = parseInt(wait, 10);
index = findThrottler(target, method, this._throttlers);
if (index > -1) { return this._throttlers[index]; } // throttled
timer = this._platform.setTimeout(function() {
if (!immediate) {
backburner.run.apply(backburner, args);
}
var index = findThrottler(target, method, backburner._throttlers);
if (index > -1) {
backburner._throttlers.splice(index, 1);
}
}, wait);
if (immediate) {
this.run.apply(this, args);
}
throttler = [target, method, timer];
this._throttlers.push(throttler);
return throttler;
},
debounce: function(target, method /* , args, wait, [immediate] */) {
var backburner = this;
var args = new Array(arguments.length);
for (var i = 0; i < arguments.length; i++) {
args[i] = arguments[i];
}
var immediate = args.pop();
var wait, index, debouncee, timer;
if (isNumber(immediate) || isString(immediate)) {
wait = immediate;
immediate = false;
} else {
wait = args.pop();
}
wait = parseInt(wait, 10);
// Remove debouncee
index = findDebouncee(target, method, this._debouncees);
if (index > -1) {
debouncee = this._debouncees[index];
this._debouncees.splice(index, 1);