ember-source 2.7.0.beta.3 → 2.7.0.beta.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a594c8e9c67550132a13c32311604b3a218f308c
4
- data.tar.gz: cf31eba641a4bb747db8e94ee843f61114e233a1
3
+ metadata.gz: ba15c71e1d4162ac3d93051e2875463a3e4aee74
4
+ data.tar.gz: 21b249f35bb90adbabe4ba379b025f373b260c4a
5
5
  SHA512:
6
- metadata.gz: f3a9c579776bf514d9f2cf08f04b458d247be9519f0b589d5c3346b5ef33062bba753d76ca52f8858086cd6f7d71e50492f4b9f5da885fa2a303c2fdd569b793
7
- data.tar.gz: 4faa2a66d654c9011855ec0574fdf4a13a8125083eb3e14ce55ad796ac9a591fb6a5e5cc0524e369aaced90a07608f4787ebe3bb5e0c26f9f2799131a62b1f8d
6
+ metadata.gz: c15c178aee9b7ee90c15c06304405da38de486e87809e37fa7526b39d72c7a83286c762462cfaeb217f9ae2bcc4bd4b9a91530655d26b2518100044a245cd186
7
+ data.tar.gz: e3f30720d2f0a8770ac5c9f049f43b0e7df80db75285ae06d2de3e3cc9d17450f1985a3339a832ac6589bbec769ad720b20ef45f0bb24fb57912a069976fa452
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.7.0-beta.3
1
+ 2.7.0-beta.4
@@ -6,7 +6,7 @@
6
6
  * Portions Copyright 2008-2011 Apple Inc. All rights reserved.
7
7
  * @license Licensed under MIT license
8
8
  * See https://raw.github.com/emberjs/ember.js/master/LICENSE
9
- * @version 2.7.0-beta.3
9
+ * @version 2.7.0-beta.4
10
10
  */
11
11
 
12
12
  var enifed, requireModule, require, Ember;
@@ -112,1053 +112,1053 @@ var mainContext = this;
112
112
  }
113
113
  })();
114
114
 
115
- enifed("backburner/binary-search", ["exports"], function (exports) {
116
- "use strict";
115
+ enifed('backburner', ['exports', 'backburner/utils', 'backburner/platform', 'backburner/binary-search', 'backburner/deferred-action-queues'], function (exports, _backburnerUtils, _backburnerPlatform, _backburnerBinarySearch, _backburnerDeferredActionQueues) {
116
+ 'use strict';
117
117
 
118
- exports.default = binarySearch;
118
+ exports.default = Backburner;
119
119
 
120
- function binarySearch(time, timers) {
121
- var start = 0;
122
- var end = timers.length - 2;
123
- var middle, l;
120
+ function Backburner(queueNames, options) {
121
+ this.queueNames = queueNames;
122
+ this.options = options || {};
123
+ if (!this.options.defaultQueue) {
124
+ this.options.defaultQueue = queueNames[0];
125
+ }
126
+ this.instanceStack = [];
127
+ this._debouncees = [];
128
+ this._throttlers = [];
129
+ this._eventCallbacks = {
130
+ end: [],
131
+ begin: []
132
+ };
124
133
 
125
- while (start < end) {
126
- // since timers is an array of pairs 'l' will always
127
- // be an integer
128
- l = (end - start) / 2;
134
+ var _this = this;
135
+ this._boundClearItems = function () {
136
+ clearItems();
137
+ };
129
138
 
130
- // compensate for the index in case even number
131
- // of pairs inside timers
132
- middle = start + l - l % 2;
139
+ this._timerTimeoutId = undefined;
140
+ this._timers = [];
133
141
 
134
- if (time >= timers[middle]) {
135
- start = middle + 2;
136
- } else {
137
- end = middle;
138
- }
139
- }
142
+ this._platform = this.options._platform || _backburnerPlatform.default;
140
143
 
141
- return time >= timers[start] ? start + 2 : start;
144
+ this._boundRunExpiredTimers = function () {
145
+ _this._runExpiredTimers();
146
+ };
142
147
  }
143
- });
144
- enifed('backburner/deferred-action-queues', ['exports', 'backburner/utils', 'backburner/queue'], function (exports, _backburnerUtils, _backburnerQueue) {
145
- 'use strict';
146
148
 
147
- exports.default = DeferredActionQueues;
149
+ Backburner.prototype = {
150
+ begin: function () {
151
+ var options = this.options;
152
+ var onBegin = options && options.onBegin;
153
+ var previousInstance = this.currentInstance;
148
154
 
149
- function DeferredActionQueues(queueNames, options) {
150
- var queues = this.queues = {};
151
- this.queueNames = queueNames = queueNames || [];
155
+ if (previousInstance) {
156
+ this.instanceStack.push(previousInstance);
157
+ }
152
158
 
153
- this.options = options;
159
+ this.currentInstance = new _backburnerDeferredActionQueues.default(this.queueNames, options);
160
+ this._trigger('begin', this.currentInstance, previousInstance);
161
+ if (onBegin) {
162
+ onBegin(this.currentInstance, previousInstance);
163
+ }
164
+ },
154
165
 
155
- _backburnerUtils.each(queueNames, function (queueName) {
156
- queues[queueName] = new _backburnerQueue.default(queueName, options[queueName], options);
157
- });
158
- }
166
+ end: function () {
167
+ var options = this.options;
168
+ var onEnd = options && options.onEnd;
169
+ var currentInstance = this.currentInstance;
170
+ var nextInstance = null;
159
171
 
160
- function noSuchQueue(name) {
161
- throw new Error('You attempted to schedule an action in a queue (' + name + ') that doesn\'t exist');
162
- }
172
+ // Prevent double-finally bug in Safari 6.0.2 and iOS 6
173
+ // This bug appears to be resolved in Safari 6.0.5 and iOS 7
174
+ var finallyAlreadyCalled = false;
175
+ try {
176
+ currentInstance.flush();
177
+ } finally {
178
+ if (!finallyAlreadyCalled) {
179
+ finallyAlreadyCalled = true;
163
180
 
164
- function noSuchMethod(name) {
165
- throw new Error('You attempted to schedule an action in a queue (' + name + ') for a method that doesn\'t exist');
166
- }
181
+ this.currentInstance = null;
167
182
 
168
- DeferredActionQueues.prototype = {
169
- schedule: function (name, target, method, args, onceFlag, stack) {
170
- var queues = this.queues;
171
- var queue = queues[name];
183
+ if (this.instanceStack.length) {
184
+ nextInstance = this.instanceStack.pop();
185
+ this.currentInstance = nextInstance;
186
+ }
187
+ this._trigger('end', currentInstance, nextInstance);
188
+ if (onEnd) {
189
+ onEnd(currentInstance, nextInstance);
190
+ }
191
+ }
192
+ }
193
+ },
172
194
 
173
- if (!queue) {
174
- noSuchQueue(name);
195
+ /**
196
+ Trigger an event. Supports up to two arguments. Designed around
197
+ triggering transition events from one run loop instance to the
198
+ next, which requires an argument for the first instance and then
199
+ an argument for the next instance.
200
+ @private
201
+ @method _trigger
202
+ @param {String} eventName
203
+ @param {any} arg1
204
+ @param {any} arg2
205
+ */
206
+ _trigger: function (eventName, arg1, arg2) {
207
+ var callbacks = this._eventCallbacks[eventName];
208
+ if (callbacks) {
209
+ for (var i = 0; i < callbacks.length; i++) {
210
+ callbacks[i](arg1, arg2);
211
+ }
175
212
  }
213
+ },
176
214
 
177
- if (!method) {
178
- noSuchMethod(name);
215
+ on: function (eventName, callback) {
216
+ if (typeof callback !== 'function') {
217
+ throw new TypeError('Callback must be a function');
218
+ }
219
+ var callbacks = this._eventCallbacks[eventName];
220
+ if (callbacks) {
221
+ callbacks.push(callback);
222
+ } else {
223
+ throw new TypeError('Cannot on() event "' + eventName + '" because it does not exist');
179
224
  }
225
+ },
180
226
 
181
- if (onceFlag) {
182
- return queue.pushUnique(target, method, args, stack);
227
+ off: function (eventName, callback) {
228
+ if (eventName) {
229
+ var callbacks = this._eventCallbacks[eventName];
230
+ var callbackFound = false;
231
+ if (!callbacks) return;
232
+ if (callback) {
233
+ for (var i = 0; i < callbacks.length; i++) {
234
+ if (callbacks[i] === callback) {
235
+ callbackFound = true;
236
+ callbacks.splice(i, 1);
237
+ i--;
238
+ }
239
+ }
240
+ }
241
+ if (!callbackFound) {
242
+ throw new TypeError('Cannot off() callback that does not exist');
243
+ }
183
244
  } else {
184
- return queue.push(target, method, args, stack);
245
+ throw new TypeError('Cannot off() event "' + eventName + '" because it does not exist');
185
246
  }
186
247
  },
187
248
 
188
- flush: function () {
189
- var queues = this.queues;
190
- var queueNames = this.queueNames;
191
- var queueName, queue;
192
- var queueNameIndex = 0;
193
- var numberOfQueues = queueNames.length;
249
+ run: function () /* target, method, args */{
250
+ var length = arguments.length;
251
+ var method, target, args;
194
252
 
195
- while (queueNameIndex < numberOfQueues) {
196
- queueName = queueNames[queueNameIndex];
197
- queue = queues[queueName];
253
+ if (length === 1) {
254
+ method = arguments[0];
255
+ target = null;
256
+ } else {
257
+ target = arguments[0];
258
+ method = arguments[1];
259
+ }
198
260
 
199
- var numberOfQueueItems = queue._queue.length;
261
+ if (_backburnerUtils.isString(method)) {
262
+ method = target[method];
263
+ }
200
264
 
201
- if (numberOfQueueItems === 0) {
202
- queueNameIndex++;
203
- } else {
204
- queue.flush(false /* async */);
205
- queueNameIndex = 0;
265
+ if (length > 2) {
266
+ args = new Array(length - 2);
267
+ for (var i = 0, l = length - 2; i < l; i++) {
268
+ args[i] = arguments[i + 2];
206
269
  }
270
+ } else {
271
+ args = [];
207
272
  }
208
- }
209
- };
210
- });
211
- enifed('backburner/platform', ['exports'], function (exports) {
212
- 'use strict';
213
273
 
214
- var GlobalContext;
274
+ var onError = getOnError(this.options);
215
275
 
216
- /* global self */
217
- if (typeof self === 'object') {
218
- GlobalContext = self;
276
+ this.begin();
219
277
 
220
- /* global global */
221
- } else if (typeof global === 'object') {
222
- GlobalContext = global;
278
+ // guard against Safari 6's double-finally bug
279
+ var didFinally = false;
223
280
 
224
- /* global window */
225
- } else if (typeof window === 'object') {
226
- GlobalContext = window;
281
+ if (onError) {
282
+ try {
283
+ return method.apply(target, args);
284
+ } catch (error) {
285
+ onError(error);
286
+ } finally {
287
+ if (!didFinally) {
288
+ didFinally = true;
289
+ this.end();
290
+ }
291
+ }
227
292
  } else {
228
- throw new Error('no global: `self`, `global` nor `window` was found');
293
+ try {
294
+ return method.apply(target, args);
295
+ } finally {
296
+ if (!didFinally) {
297
+ didFinally = true;
298
+ this.end();
299
+ }
300
+ }
229
301
  }
302
+ },
230
303
 
231
- exports.default = GlobalContext;
232
- });
233
- enifed('backburner/queue', ['exports', 'backburner/utils'], function (exports, _backburnerUtils) {
234
- 'use strict';
304
+ /*
305
+ Join the passed method with an existing queue and execute immediately,
306
+ if there isn't one use `Backburner#run`.
307
+ The join method is like the run method except that it will schedule into
308
+ an existing queue if one already exists. In either case, the join method will
309
+ immediately execute the passed in function and return its result.
310
+ @method join
311
+ @param {Object} target
312
+ @param {Function} method The method to be executed
313
+ @param {any} args The method arguments
314
+ @return method result
315
+ */
316
+ join: function () /* target, method, args */{
317
+ if (!this.currentInstance) {
318
+ return this.run.apply(this, arguments);
319
+ }
235
320
 
236
- exports.default = Queue;
237
-
238
- function Queue(name, options, globalOptions) {
239
- this.name = name;
240
- this.globalOptions = globalOptions || {};
241
- this.options = options;
242
- this._queue = [];
243
- this.targetQueues = {};
244
- this._queueBeingFlushed = undefined;
245
- }
246
-
247
- Queue.prototype = {
248
- push: function (target, method, args, stack) {
249
- var queue = this._queue;
250
- queue.push(target, method, args, stack);
251
-
252
- return {
253
- queue: this,
254
- target: target,
255
- method: method
256
- };
257
- },
321
+ var length = arguments.length;
322
+ var method, target;
258
323
 
259
- pushUniqueWithoutGuid: function (target, method, args, stack) {
260
- var queue = this._queue;
324
+ if (length === 1) {
325
+ method = arguments[0];
326
+ target = null;
327
+ } else {
328
+ target = arguments[0];
329
+ method = arguments[1];
330
+ }
261
331
 
262
- for (var i = 0, l = queue.length; i < l; i += 4) {
263
- var currentTarget = queue[i];
264
- var currentMethod = queue[i + 1];
332
+ if (_backburnerUtils.isString(method)) {
333
+ method = target[method];
334
+ }
265
335
 
266
- if (currentTarget === target && currentMethod === method) {
267
- queue[i + 2] = args; // replace args
268
- queue[i + 3] = stack; // replace stack
269
- return;
336
+ if (length === 1) {
337
+ return method();
338
+ } else if (length === 2) {
339
+ return method.call(target);
340
+ } else {
341
+ var args = new Array(length - 2);
342
+ for (var i = 0, l = length - 2; i < l; i++) {
343
+ args[i] = arguments[i + 2];
270
344
  }
345
+ return method.apply(target, args);
271
346
  }
272
-
273
- queue.push(target, method, args, stack);
274
347
  },
275
348
 
276
- targetQueue: function (targetQueue, target, method, args, stack) {
277
- var queue = this._queue;
278
-
279
- for (var i = 0, l = targetQueue.length; i < l; i += 2) {
280
- var currentMethod = targetQueue[i];
281
- var currentIndex = targetQueue[i + 1];
349
+ /*
350
+ Defer the passed function to run inside the specified queue.
351
+ @method defer
352
+ @param {String} queueName
353
+ @param {Object} target
354
+ @param {Function|String} method The method or method name to be executed
355
+ @param {any} args The method arguments
356
+ @return method result
357
+ */
358
+ defer: function (queueName /* , target, method, args */) {
359
+ var length = arguments.length;
360
+ var method, target, args;
282
361
 
283
- if (currentMethod === method) {
284
- queue[currentIndex + 2] = args; // replace args
285
- queue[currentIndex + 3] = stack; // replace stack
286
- return;
287
- }
362
+ if (length === 2) {
363
+ method = arguments[1];
364
+ target = null;
365
+ } else {
366
+ target = arguments[1];
367
+ method = arguments[2];
288
368
  }
289
369
 
290
- targetQueue.push(method, queue.push(target, method, args, stack) - 4);
291
- },
370
+ if (_backburnerUtils.isString(method)) {
371
+ method = target[method];
372
+ }
292
373
 
293
- pushUniqueWithGuid: function (guid, target, method, args, stack) {
294
- var hasLocalQueue = this.targetQueues[guid];
374
+ var stack = this.DEBUG ? new Error() : undefined;
295
375
 
296
- if (hasLocalQueue) {
297
- this.targetQueue(hasLocalQueue, target, method, args, stack);
376
+ if (length > 3) {
377
+ args = new Array(length - 3);
378
+ for (var i = 3; i < length; i++) {
379
+ args[i - 3] = arguments[i];
380
+ }
298
381
  } else {
299
- this.targetQueues[guid] = [method, this._queue.push(target, method, args, stack) - 4];
382
+ args = undefined;
300
383
  }
301
384
 
302
- return {
303
- queue: this,
304
- target: target,
305
- method: method
306
- };
385
+ if (!this.currentInstance) {
386
+ createAutorun(this);
387
+ }
388
+ return this.currentInstance.schedule(queueName, target, method, args, false, stack);
307
389
  },
308
390
 
309
- pushUnique: function (target, method, args, stack) {
310
- var KEY = this.globalOptions.GUID_KEY;
391
+ deferOnce: function (queueName /* , target, method, args */) {
392
+ var length = arguments.length;
393
+ var method, target, args;
311
394
 
312
- if (target && KEY) {
313
- var guid = target[KEY];
314
- if (guid) {
315
- return this.pushUniqueWithGuid(guid, target, method, args, stack);
316
- }
395
+ if (length === 2) {
396
+ method = arguments[1];
397
+ target = null;
398
+ } else {
399
+ target = arguments[1];
400
+ method = arguments[2];
317
401
  }
318
402
 
319
- this.pushUniqueWithoutGuid(target, method, args, stack);
403
+ if (_backburnerUtils.isString(method)) {
404
+ method = target[method];
405
+ }
320
406
 
321
- return {
322
- queue: this,
323
- target: target,
324
- method: method
325
- };
326
- },
407
+ var stack = this.DEBUG ? new Error() : undefined;
327
408
 
328
- invoke: function (target, method, args, _, _errorRecordedForStack) {
329
- if (args && args.length > 0) {
330
- method.apply(target, args);
409
+ if (length > 3) {
410
+ args = new Array(length - 3);
411
+ for (var i = 3; i < length; i++) {
412
+ args[i - 3] = arguments[i];
413
+ }
331
414
  } else {
332
- method.call(target);
415
+ args = undefined;
333
416
  }
334
- },
335
417
 
336
- invokeWithOnError: function (target, method, args, onError, errorRecordedForStack) {
337
- try {
338
- if (args && args.length > 0) {
339
- method.apply(target, args);
340
- } else {
341
- method.call(target);
342
- }
343
- } catch (error) {
344
- onError(error, errorRecordedForStack);
418
+ if (!this.currentInstance) {
419
+ createAutorun(this);
345
420
  }
421
+ return this.currentInstance.schedule(queueName, target, method, args, true, stack);
346
422
  },
347
423
 
348
- flush: function (sync) {
349
- var queue = this._queue;
350
- var length = queue.length;
424
+ setTimeout: function () {
425
+ var l = arguments.length;
426
+ var args = new Array(l);
351
427
 
352
- if (length === 0) {
353
- return;
428
+ for (var x = 0; x < l; x++) {
429
+ args[x] = arguments[x];
354
430
  }
355
431
 
356
- var globalOptions = this.globalOptions;
357
- var options = this.options;
358
- var before = options && options.before;
359
- var after = options && options.after;
360
- var onError = globalOptions.onError || globalOptions.onErrorTarget && globalOptions.onErrorTarget[globalOptions.onErrorMethod];
361
- var target, method, args, errorRecordedForStack;
362
- var invoke = onError ? this.invokeWithOnError : this.invoke;
363
-
364
- this.targetQueues = Object.create(null);
365
- var queueItems = this._queueBeingFlushed = this._queue.slice();
366
- this._queue = [];
367
-
368
- if (before) {
369
- before();
370
- }
432
+ var length = args.length,
433
+ method,
434
+ wait,
435
+ target,
436
+ methodOrTarget,
437
+ methodOrWait,
438
+ methodOrArgs;
371
439
 
372
- for (var i = 0; i < length; i += 4) {
373
- target = queueItems[i];
374
- method = queueItems[i + 1];
375
- args = queueItems[i + 2];
376
- errorRecordedForStack = queueItems[i + 3]; // Debugging assistance
440
+ if (length === 0) {
441
+ return;
442
+ } else if (length === 1) {
443
+ method = args.shift();
444
+ wait = 0;
445
+ } else if (length === 2) {
446
+ methodOrTarget = args[0];
447
+ methodOrWait = args[1];
377
448
 
378
- if (_backburnerUtils.isString(method)) {
379
- method = target[method];
449
+ if (_backburnerUtils.isFunction(methodOrWait) || _backburnerUtils.isFunction(methodOrTarget[methodOrWait])) {
450
+ target = args.shift();
451
+ method = args.shift();
452
+ wait = 0;
453
+ } else if (_backburnerUtils.isCoercableNumber(methodOrWait)) {
454
+ method = args.shift();
455
+ wait = args.shift();
456
+ } else {
457
+ method = args.shift();
458
+ wait = 0;
380
459
  }
460
+ } else {
461
+ var last = args[args.length - 1];
381
462
 
382
- // method could have been nullified / canceled during flush
383
- if (method) {
384
- //
385
- // ** Attention intrepid developer **
386
- //
387
- // To find out the stack of this task when it was scheduled onto
388
- // the run loop, add the following to your app.js:
389
- //
390
- // Ember.run.backburner.DEBUG = true; // NOTE: This slows your app, don't leave it on in production.
391
- //
392
- // Once that is in place, when you are at a breakpoint and navigate
393
- // here in the stack explorer, you can look at `errorRecordedForStack.stack`,
394
- // which will be the captured stack when this job was scheduled.
395
- //
396
- invoke(target, method, args, onError, errorRecordedForStack);
463
+ if (_backburnerUtils.isCoercableNumber(last)) {
464
+ wait = args.pop();
465
+ } else {
466
+ wait = 0;
397
467
  }
398
- }
399
468
 
400
- if (after) {
401
- after();
469
+ methodOrTarget = args[0];
470
+ methodOrArgs = args[1];
471
+
472
+ if (_backburnerUtils.isFunction(methodOrArgs) || _backburnerUtils.isString(methodOrArgs) && methodOrTarget !== null && methodOrArgs in methodOrTarget) {
473
+ target = args.shift();
474
+ method = args.shift();
475
+ } else {
476
+ method = args.shift();
477
+ }
402
478
  }
403
479
 
404
- this._queueBeingFlushed = undefined;
480
+ var executeAt = Date.now() + parseInt(wait !== wait ? 0 : wait, 10);
405
481
 
406
- if (sync !== false && this._queue.length > 0) {
407
- // check if new items have been added
408
- this.flush(true);
482
+ if (_backburnerUtils.isString(method)) {
483
+ method = target[method];
409
484
  }
410
- },
411
485
 
412
- cancel: function (actionToCancel) {
413
- var queue = this._queue,
414
- currentTarget,
415
- currentMethod,
416
- i,
417
- l;
418
- var target = actionToCancel.target;
419
- var method = actionToCancel.method;
420
- var GUID_KEY = this.globalOptions.GUID_KEY;
421
-
422
- if (GUID_KEY && this.targetQueues && target) {
423
- var targetQueue = this.targetQueues[target[GUID_KEY]];
486
+ var onError = getOnError(this.options);
424
487
 
425
- if (targetQueue) {
426
- for (i = 0, l = targetQueue.length; i < l; i++) {
427
- if (targetQueue[i] === method) {
428
- targetQueue.splice(i, 1);
429
- }
488
+ function fn() {
489
+ if (onError) {
490
+ try {
491
+ method.apply(target, args);
492
+ } catch (e) {
493
+ onError(e);
430
494
  }
495
+ } else {
496
+ method.apply(target, args);
431
497
  }
432
498
  }
433
499
 
434
- for (i = 0, l = queue.length; i < l; i += 4) {
435
- currentTarget = queue[i];
436
- currentMethod = queue[i + 1];
500
+ return this._setTimeout(fn, executeAt);
501
+ },
437
502
 
438
- if (currentTarget === target && currentMethod === method) {
439
- queue.splice(i, 4);
440
- return true;
441
- }
503
+ _setTimeout: function (fn, executeAt) {
504
+ if (this._timers.length === 0) {
505
+ this._timers.push(executeAt, fn);
506
+ this._installTimerTimeout();
507
+ return fn;
442
508
  }
443
509
 
444
- // if not found in current queue
445
- // could be in the queue that is being flushed
446
- queue = this._queueBeingFlushed;
510
+ // find position to insert
511
+ var i = _backburnerBinarySearch.default(executeAt, this._timers);
447
512
 
448
- if (!queue) {
449
- return;
513
+ this._timers.splice(i, 0, executeAt, fn);
514
+
515
+ // we should be the new earliest timer if i == 0
516
+ if (i === 0) {
517
+ this._reinstallTimerTimeout();
450
518
  }
451
519
 
452
- for (i = 0, l = queue.length; i < l; i += 4) {
453
- currentTarget = queue[i];
454
- currentMethod = queue[i + 1];
520
+ return fn;
521
+ },
455
522
 
456
- if (currentTarget === target && currentMethod === method) {
457
- // don't mess with array during flush
458
- // just nullify the method
459
- queue[i + 1] = null;
460
- return true;
461
- }
523
+ throttle: function (target, method /* , args, wait, [immediate] */) {
524
+ var backburner = this;
525
+ var args = new Array(arguments.length);
526
+ for (var i = 0; i < arguments.length; i++) {
527
+ args[i] = arguments[i];
462
528
  }
463
- }
464
- };
465
- });
466
- enifed('backburner/utils', ['exports'], function (exports) {
467
- 'use strict';
468
-
469
- exports.each = each;
470
- exports.isString = isString;
471
- exports.isFunction = isFunction;
472
- exports.isNumber = isNumber;
473
- exports.isCoercableNumber = isCoercableNumber;
474
- var NUMBER = /\d+/;
529
+ var immediate = args.pop();
530
+ var wait, throttler, index, timer;
475
531
 
476
- function each(collection, callback) {
477
- for (var i = 0; i < collection.length; i++) {
478
- callback(collection[i]);
479
- }
480
- }
532
+ if (_backburnerUtils.isNumber(immediate) || _backburnerUtils.isString(immediate)) {
533
+ wait = immediate;
534
+ immediate = true;
535
+ } else {
536
+ wait = args.pop();
537
+ }
481
538
 
482
- function isString(suspect) {
483
- return typeof suspect === 'string';
484
- }
539
+ wait = parseInt(wait, 10);
485
540
 
486
- function isFunction(suspect) {
487
- return typeof suspect === 'function';
488
- }
541
+ index = findThrottler(target, method, this._throttlers);
542
+ if (index > -1) {
543
+ return this._throttlers[index];
544
+ } // throttled
489
545
 
490
- function isNumber(suspect) {
491
- return typeof suspect === 'number';
492
- }
546
+ timer = this._platform.setTimeout(function () {
547
+ if (!immediate) {
548
+ backburner.run.apply(backburner, args);
549
+ }
550
+ var index = findThrottler(target, method, backburner._throttlers);
551
+ if (index > -1) {
552
+ backburner._throttlers.splice(index, 1);
553
+ }
554
+ }, wait);
493
555
 
494
- function isCoercableNumber(number) {
495
- return isNumber(number) || NUMBER.test(number);
496
- }
497
- });
498
- enifed('backburner', ['exports', 'backburner/utils', 'backburner/platform', 'backburner/binary-search', 'backburner/deferred-action-queues'], function (exports, _backburnerUtils, _backburnerPlatform, _backburnerBinarySearch, _backburnerDeferredActionQueues) {
499
- 'use strict';
556
+ if (immediate) {
557
+ this.run.apply(this, args);
558
+ }
500
559
 
501
- exports.default = Backburner;
560
+ throttler = [target, method, timer];
502
561
 
503
- function Backburner(queueNames, options) {
504
- this.queueNames = queueNames;
505
- this.options = options || {};
506
- if (!this.options.defaultQueue) {
507
- this.options.defaultQueue = queueNames[0];
508
- }
509
- this.instanceStack = [];
510
- this._debouncees = [];
511
- this._throttlers = [];
512
- this._eventCallbacks = {
513
- end: [],
514
- begin: []
515
- };
562
+ this._throttlers.push(throttler);
516
563
 
517
- var _this = this;
518
- this._boundClearItems = function () {
519
- clearItems();
520
- };
564
+ return throttler;
565
+ },
521
566
 
522
- this._timerTimeoutId = undefined;
523
- this._timers = [];
567
+ debounce: function (target, method /* , args, wait, [immediate] */) {
568
+ var backburner = this;
569
+ var args = new Array(arguments.length);
570
+ for (var i = 0; i < arguments.length; i++) {
571
+ args[i] = arguments[i];
572
+ }
524
573
 
525
- this._platform = this.options._platform || _backburnerPlatform.default;
574
+ var immediate = args.pop();
575
+ var wait, index, debouncee, timer;
526
576
 
527
- this._boundRunExpiredTimers = function () {
528
- _this._runExpiredTimers();
529
- };
530
- }
577
+ if (_backburnerUtils.isNumber(immediate) || _backburnerUtils.isString(immediate)) {
578
+ wait = immediate;
579
+ immediate = false;
580
+ } else {
581
+ wait = args.pop();
582
+ }
531
583
 
532
- Backburner.prototype = {
533
- begin: function () {
534
- var options = this.options;
535
- var onBegin = options && options.onBegin;
536
- var previousInstance = this.currentInstance;
584
+ wait = parseInt(wait, 10);
585
+ // Remove debouncee
586
+ index = findDebouncee(target, method, this._debouncees);
537
587
 
538
- if (previousInstance) {
539
- this.instanceStack.push(previousInstance);
588
+ if (index > -1) {
589
+ debouncee = this._debouncees[index];
590
+ this._debouncees.splice(index, 1);
591
+ this._platform.clearTimeout(debouncee[2]);
540
592
  }
541
593
 
542
- this.currentInstance = new _backburnerDeferredActionQueues.default(this.queueNames, options);
543
- this._trigger('begin', this.currentInstance, previousInstance);
544
- if (onBegin) {
545
- onBegin(this.currentInstance, previousInstance);
594
+ timer = this._platform.setTimeout(function () {
595
+ if (!immediate) {
596
+ backburner.run.apply(backburner, args);
597
+ }
598
+ var index = findDebouncee(target, method, backburner._debouncees);
599
+ if (index > -1) {
600
+ backburner._debouncees.splice(index, 1);
601
+ }
602
+ }, wait);
603
+
604
+ if (immediate && index === -1) {
605
+ backburner.run.apply(backburner, args);
546
606
  }
607
+
608
+ debouncee = [target, method, timer];
609
+
610
+ backburner._debouncees.push(debouncee);
611
+
612
+ return debouncee;
547
613
  },
548
614
 
549
- end: function () {
550
- var options = this.options;
551
- var onEnd = options && options.onEnd;
552
- var currentInstance = this.currentInstance;
553
- var nextInstance = null;
615
+ cancelTimers: function () {
616
+ _backburnerUtils.each(this._throttlers, this._boundClearItems);
617
+ this._throttlers = [];
554
618
 
555
- // Prevent double-finally bug in Safari 6.0.2 and iOS 6
556
- // This bug appears to be resolved in Safari 6.0.5 and iOS 7
557
- var finallyAlreadyCalled = false;
558
- try {
559
- currentInstance.flush();
560
- } finally {
561
- if (!finallyAlreadyCalled) {
562
- finallyAlreadyCalled = true;
619
+ _backburnerUtils.each(this._debouncees, this._boundClearItems);
620
+ this._debouncees = [];
563
621
 
564
- this.currentInstance = null;
622
+ this._clearTimerTimeout();
623
+ this._timers = [];
565
624
 
566
- if (this.instanceStack.length) {
567
- nextInstance = this.instanceStack.pop();
568
- this.currentInstance = nextInstance;
569
- }
570
- this._trigger('end', currentInstance, nextInstance);
571
- if (onEnd) {
572
- onEnd(currentInstance, nextInstance);
573
- }
574
- }
625
+ if (this._autorun) {
626
+ this._platform.clearTimeout(this._autorun);
627
+ this._autorun = null;
575
628
  }
576
629
  },
577
630
 
578
- /**
579
- Trigger an event. Supports up to two arguments. Designed around
580
- triggering transition events from one run loop instance to the
581
- next, which requires an argument for the first instance and then
582
- an argument for the next instance.
583
- @private
584
- @method _trigger
585
- @param {String} eventName
586
- @param {any} arg1
587
- @param {any} arg2
588
- */
589
- _trigger: function (eventName, arg1, arg2) {
590
- var callbacks = this._eventCallbacks[eventName];
591
- if (callbacks) {
592
- for (var i = 0; i < callbacks.length; i++) {
593
- callbacks[i](arg1, arg2);
594
- }
595
- }
596
- },
597
-
598
- on: function (eventName, callback) {
599
- if (typeof callback !== 'function') {
600
- throw new TypeError('Callback must be a function');
601
- }
602
- var callbacks = this._eventCallbacks[eventName];
603
- if (callbacks) {
604
- callbacks.push(callback);
605
- } else {
606
- throw new TypeError('Cannot on() event "' + eventName + '" because it does not exist');
607
- }
631
+ hasTimers: function () {
632
+ return !!this._timers.length || !!this._debouncees.length || !!this._throttlers.length || this._autorun;
608
633
  },
609
634
 
610
- off: function (eventName, callback) {
611
- if (eventName) {
612
- var callbacks = this._eventCallbacks[eventName];
613
- var callbackFound = false;
614
- if (!callbacks) return;
615
- if (callback) {
616
- for (var i = 0; i < callbacks.length; i++) {
617
- if (callbacks[i] === callback) {
618
- callbackFound = true;
619
- callbacks.splice(i, 1);
620
- i--;
635
+ cancel: function (timer) {
636
+ var timerType = typeof timer;
637
+
638
+ if (timer && timerType === 'object' && timer.queue && timer.method) {
639
+ // we're cancelling a deferOnce
640
+ return timer.queue.cancel(timer);
641
+ } else if (timerType === 'function') {
642
+ // we're cancelling a setTimeout
643
+ for (var i = 0, l = this._timers.length; i < l; i += 2) {
644
+ if (this._timers[i + 1] === timer) {
645
+ this._timers.splice(i, 2); // remove the two elements
646
+ if (i === 0) {
647
+ this._reinstallTimerTimeout();
621
648
  }
649
+ return true;
622
650
  }
623
651
  }
624
- if (!callbackFound) {
625
- throw new TypeError('Cannot off() callback that does not exist');
626
- }
652
+ } else if (Object.prototype.toString.call(timer) === '[object Array]') {
653
+ // we're cancelling a throttle or debounce
654
+ return this._cancelItem(findThrottler, this._throttlers, timer) || this._cancelItem(findDebouncee, this._debouncees, timer);
627
655
  } else {
628
- throw new TypeError('Cannot off() event "' + eventName + '" because it does not exist');
656
+ return; // timer was null or not a timer
629
657
  }
630
658
  },
631
659
 
632
- run: function () /* target, method, args */{
633
- var length = arguments.length;
634
- var method, target, args;
635
-
636
- if (length === 1) {
637
- method = arguments[0];
638
- target = null;
639
- } else {
640
- target = arguments[0];
641
- method = arguments[1];
642
- }
643
-
644
- if (_backburnerUtils.isString(method)) {
645
- method = target[method];
646
- }
660
+ _cancelItem: function (findMethod, array, timer) {
661
+ var item, index;
647
662
 
648
- if (length > 2) {
649
- args = new Array(length - 2);
650
- for (var i = 0, l = length - 2; i < l; i++) {
651
- args[i] = arguments[i + 2];
652
- }
653
- } else {
654
- args = [];
663
+ if (timer.length < 3) {
664
+ return false;
655
665
  }
656
666
 
657
- var onError = getOnError(this.options);
667
+ index = findMethod(timer[0], timer[1], array);
658
668
 
659
- this.begin();
669
+ if (index > -1) {
660
670
 
661
- // guard against Safari 6's double-finally bug
662
- var didFinally = false;
671
+ item = array[index];
663
672
 
664
- if (onError) {
665
- try {
666
- return method.apply(target, args);
667
- } catch (error) {
668
- onError(error);
669
- } finally {
670
- if (!didFinally) {
671
- didFinally = true;
672
- this.end();
673
- }
674
- }
675
- } else {
676
- try {
677
- return method.apply(target, args);
678
- } finally {
679
- if (!didFinally) {
680
- didFinally = true;
681
- this.end();
682
- }
673
+ if (item[2] === timer[2]) {
674
+ array.splice(index, 1);
675
+ this._platform.clearTimeout(timer[2]);
676
+ return true;
683
677
  }
684
678
  }
685
- },
686
-
687
- /*
688
- Join the passed method with an existing queue and execute immediately,
689
- if there isn't one use `Backburner#run`.
690
- The join method is like the run method except that it will schedule into
691
- an existing queue if one already exists. In either case, the join method will
692
- immediately execute the passed in function and return its result.
693
- @method join
694
- @param {Object} target
695
- @param {Function} method The method to be executed
696
- @param {any} args The method arguments
697
- @return method result
698
- */
699
- join: function () /* target, method, args */{
700
- if (!this.currentInstance) {
701
- return this.run.apply(this, arguments);
702
- }
703
679
 
704
- var length = arguments.length;
705
- var method, target;
706
-
707
- if (length === 1) {
708
- method = arguments[0];
709
- target = null;
710
- } else {
711
- target = arguments[0];
712
- method = arguments[1];
713
- }
680
+ return false;
681
+ },
714
682
 
715
- if (_backburnerUtils.isString(method)) {
716
- method = target[method];
717
- }
683
+ _runExpiredTimers: function () {
684
+ this._timerTimeoutId = undefined;
685
+ this.run(this, this._scheduleExpiredTimers);
686
+ },
718
687
 
719
- if (length === 1) {
720
- return method();
721
- } else if (length === 2) {
722
- return method.call(target);
723
- } else {
724
- var args = new Array(length - 2);
725
- for (var i = 0, l = length - 2; i < l; i++) {
726
- args[i] = arguments[i + 2];
688
+ _scheduleExpiredTimers: function () {
689
+ var n = Date.now();
690
+ var timers = this._timers;
691
+ var i = 0;
692
+ var l = timers.length;
693
+ for (; i < l; i += 2) {
694
+ var executeAt = timers[i];
695
+ var fn = timers[i + 1];
696
+ if (executeAt <= n) {
697
+ this.schedule(this.options.defaultQueue, null, fn);
698
+ } else {
699
+ break;
727
700
  }
728
- return method.apply(target, args);
729
701
  }
702
+ timers.splice(0, i);
703
+ this._installTimerTimeout();
730
704
  },
731
705
 
732
- /*
733
- Defer the passed function to run inside the specified queue.
734
- @method defer
735
- @param {String} queueName
736
- @param {Object} target
737
- @param {Function|String} method The method or method name to be executed
738
- @param {any} args The method arguments
739
- @return method result
740
- */
741
- defer: function (queueName /* , target, method, args */) {
742
- var length = arguments.length;
743
- var method, target, args;
706
+ _reinstallTimerTimeout: function () {
707
+ this._clearTimerTimeout();
708
+ this._installTimerTimeout();
709
+ },
744
710
 
745
- if (length === 2) {
746
- method = arguments[1];
747
- target = null;
748
- } else {
749
- target = arguments[1];
750
- method = arguments[2];
711
+ _clearTimerTimeout: function () {
712
+ if (!this._timerTimeoutId) {
713
+ return;
751
714
  }
715
+ this._platform.clearTimeout(this._timerTimeoutId);
716
+ this._timerTimeoutId = undefined;
717
+ },
752
718
 
753
- if (_backburnerUtils.isString(method)) {
754
- method = target[method];
719
+ _installTimerTimeout: function () {
720
+ if (!this._timers.length) {
721
+ return;
755
722
  }
723
+ var minExpiresAt = this._timers[0];
724
+ var n = Date.now();
725
+ var wait = Math.max(0, minExpiresAt - n);
726
+ this._timerTimeoutId = this._platform.setTimeout(this._boundRunExpiredTimers, wait);
727
+ }
728
+ };
756
729
 
757
- var stack = this.DEBUG ? new Error() : undefined;
730
+ Backburner.prototype.schedule = Backburner.prototype.defer;
731
+ Backburner.prototype.scheduleOnce = Backburner.prototype.deferOnce;
732
+ Backburner.prototype.later = Backburner.prototype.setTimeout;
758
733
 
759
- if (length > 3) {
760
- args = new Array(length - 3);
761
- for (var i = 3; i < length; i++) {
762
- args[i - 3] = arguments[i];
763
- }
764
- } else {
765
- args = undefined;
766
- }
734
+ function getOnError(options) {
735
+ return options.onError || options.onErrorTarget && options.onErrorTarget[options.onErrorMethod];
736
+ }
767
737
 
768
- if (!this.currentInstance) {
769
- createAutorun(this);
770
- }
771
- return this.currentInstance.schedule(queueName, target, method, args, false, stack);
772
- },
738
+ function createAutorun(backburner) {
739
+ backburner.begin();
740
+ backburner._autorun = backburner._platform.setTimeout(function () {
741
+ backburner._autorun = null;
742
+ backburner.end();
743
+ });
744
+ }
773
745
 
774
- deferOnce: function (queueName /* , target, method, args */) {
775
- var length = arguments.length;
776
- var method, target, args;
746
+ function findDebouncee(target, method, debouncees) {
747
+ return findItem(target, method, debouncees);
748
+ }
777
749
 
778
- if (length === 2) {
779
- method = arguments[1];
780
- target = null;
781
- } else {
782
- target = arguments[1];
783
- method = arguments[2];
784
- }
750
+ function findThrottler(target, method, throttlers) {
751
+ return findItem(target, method, throttlers);
752
+ }
785
753
 
786
- if (_backburnerUtils.isString(method)) {
787
- method = target[method];
754
+ function findItem(target, method, collection) {
755
+ var item;
756
+ var index = -1;
757
+
758
+ for (var i = 0, l = collection.length; i < l; i++) {
759
+ item = collection[i];
760
+ if (item[0] === target && item[1] === method) {
761
+ index = i;
762
+ break;
788
763
  }
764
+ }
789
765
 
790
- var stack = this.DEBUG ? new Error() : undefined;
791
-
792
- if (length > 3) {
793
- args = new Array(length - 3);
794
- for (var i = 3; i < length; i++) {
795
- args[i - 3] = arguments[i];
796
- }
797
- } else {
798
- args = undefined;
799
- }
766
+ return index;
767
+ }
800
768
 
801
- if (!this.currentInstance) {
802
- createAutorun(this);
803
- }
804
- return this.currentInstance.schedule(queueName, target, method, args, true, stack);
805
- },
769
+ function clearItems(item) {
770
+ this._platform.clearTimeout(item[2]);
771
+ }
772
+ });
773
+ enifed("backburner/binary-search", ["exports"], function (exports) {
774
+ "use strict";
806
775
 
807
- setTimeout: function () {
808
- var l = arguments.length;
809
- var args = new Array(l);
776
+ exports.default = binarySearch;
810
777
 
811
- for (var x = 0; x < l; x++) {
812
- args[x] = arguments[x];
813
- }
778
+ function binarySearch(time, timers) {
779
+ var start = 0;
780
+ var end = timers.length - 2;
781
+ var middle, l;
814
782
 
815
- var length = args.length,
816
- method,
817
- wait,
818
- target,
819
- methodOrTarget,
820
- methodOrWait,
821
- methodOrArgs;
783
+ while (start < end) {
784
+ // since timers is an array of pairs 'l' will always
785
+ // be an integer
786
+ l = (end - start) / 2;
822
787
 
823
- if (length === 0) {
824
- return;
825
- } else if (length === 1) {
826
- method = args.shift();
827
- wait = 0;
828
- } else if (length === 2) {
829
- methodOrTarget = args[0];
830
- methodOrWait = args[1];
788
+ // compensate for the index in case even number
789
+ // of pairs inside timers
790
+ middle = start + l - l % 2;
831
791
 
832
- if (_backburnerUtils.isFunction(methodOrWait) || _backburnerUtils.isFunction(methodOrTarget[methodOrWait])) {
833
- target = args.shift();
834
- method = args.shift();
835
- wait = 0;
836
- } else if (_backburnerUtils.isCoercableNumber(methodOrWait)) {
837
- method = args.shift();
838
- wait = args.shift();
839
- } else {
840
- method = args.shift();
841
- wait = 0;
842
- }
792
+ if (time >= timers[middle]) {
793
+ start = middle + 2;
843
794
  } else {
844
- var last = args[args.length - 1];
845
-
846
- if (_backburnerUtils.isCoercableNumber(last)) {
847
- wait = args.pop();
848
- } else {
849
- wait = 0;
850
- }
851
-
852
- methodOrTarget = args[0];
853
- methodOrArgs = args[1];
854
-
855
- if (_backburnerUtils.isFunction(methodOrArgs) || _backburnerUtils.isString(methodOrArgs) && methodOrTarget !== null && methodOrArgs in methodOrTarget) {
856
- target = args.shift();
857
- method = args.shift();
858
- } else {
859
- method = args.shift();
860
- }
795
+ end = middle;
861
796
  }
797
+ }
862
798
 
863
- var executeAt = Date.now() + parseInt(wait !== wait ? 0 : wait, 10);
799
+ return time >= timers[start] ? start + 2 : start;
800
+ }
801
+ });
802
+ enifed('backburner/deferred-action-queues', ['exports', 'backburner/utils', 'backburner/queue'], function (exports, _backburnerUtils, _backburnerQueue) {
803
+ 'use strict';
864
804
 
865
- if (_backburnerUtils.isString(method)) {
866
- method = target[method];
867
- }
805
+ exports.default = DeferredActionQueues;
868
806
 
869
- var onError = getOnError(this.options);
807
+ function DeferredActionQueues(queueNames, options) {
808
+ var queues = this.queues = {};
809
+ this.queueNames = queueNames = queueNames || [];
870
810
 
871
- function fn() {
872
- if (onError) {
873
- try {
874
- method.apply(target, args);
875
- } catch (e) {
876
- onError(e);
877
- }
878
- } else {
879
- method.apply(target, args);
880
- }
881
- }
811
+ this.options = options;
882
812
 
883
- return this._setTimeout(fn, executeAt);
884
- },
813
+ _backburnerUtils.each(queueNames, function (queueName) {
814
+ queues[queueName] = new _backburnerQueue.default(queueName, options[queueName], options);
815
+ });
816
+ }
885
817
 
886
- _setTimeout: function (fn, executeAt) {
887
- if (this._timers.length === 0) {
888
- this._timers.push(executeAt, fn);
889
- this._installTimerTimeout();
890
- return fn;
891
- }
818
+ function noSuchQueue(name) {
819
+ throw new Error('You attempted to schedule an action in a queue (' + name + ') that doesn\'t exist');
820
+ }
892
821
 
893
- // find position to insert
894
- var i = _backburnerBinarySearch.default(executeAt, this._timers);
822
+ function noSuchMethod(name) {
823
+ throw new Error('You attempted to schedule an action in a queue (' + name + ') for a method that doesn\'t exist');
824
+ }
895
825
 
896
- this._timers.splice(i, 0, executeAt, fn);
826
+ DeferredActionQueues.prototype = {
827
+ schedule: function (name, target, method, args, onceFlag, stack) {
828
+ var queues = this.queues;
829
+ var queue = queues[name];
897
830
 
898
- // we should be the new earliest timer if i == 0
899
- if (i === 0) {
900
- this._reinstallTimerTimeout();
831
+ if (!queue) {
832
+ noSuchQueue(name);
901
833
  }
902
834
 
903
- return fn;
904
- },
905
-
906
- throttle: function (target, method /* , args, wait, [immediate] */) {
907
- var backburner = this;
908
- var args = new Array(arguments.length);
909
- for (var i = 0; i < arguments.length; i++) {
910
- args[i] = arguments[i];
835
+ if (!method) {
836
+ noSuchMethod(name);
911
837
  }
912
- var immediate = args.pop();
913
- var wait, throttler, index, timer;
914
838
 
915
- if (_backburnerUtils.isNumber(immediate) || _backburnerUtils.isString(immediate)) {
916
- wait = immediate;
917
- immediate = true;
839
+ if (onceFlag) {
840
+ return queue.pushUnique(target, method, args, stack);
918
841
  } else {
919
- wait = args.pop();
842
+ return queue.push(target, method, args, stack);
920
843
  }
844
+ },
921
845
 
922
- wait = parseInt(wait, 10);
846
+ flush: function () {
847
+ var queues = this.queues;
848
+ var queueNames = this.queueNames;
849
+ var queueName, queue;
850
+ var queueNameIndex = 0;
851
+ var numberOfQueues = queueNames.length;
923
852
 
924
- index = findThrottler(target, method, this._throttlers);
925
- if (index > -1) {
926
- return this._throttlers[index];
927
- } // throttled
853
+ while (queueNameIndex < numberOfQueues) {
854
+ queueName = queueNames[queueNameIndex];
855
+ queue = queues[queueName];
928
856
 
929
- timer = this._platform.setTimeout(function () {
930
- if (!immediate) {
931
- backburner.run.apply(backburner, args);
932
- }
933
- var index = findThrottler(target, method, backburner._throttlers);
934
- if (index > -1) {
935
- backburner._throttlers.splice(index, 1);
936
- }
937
- }, wait);
857
+ var numberOfQueueItems = queue._queue.length;
938
858
 
939
- if (immediate) {
940
- this.run.apply(this, args);
859
+ if (numberOfQueueItems === 0) {
860
+ queueNameIndex++;
861
+ } else {
862
+ queue.flush(false /* async */);
863
+ queueNameIndex = 0;
864
+ }
941
865
  }
866
+ }
867
+ };
868
+ });
869
+ enifed('backburner/platform', ['exports'], function (exports) {
870
+ 'use strict';
942
871
 
943
- throttler = [target, method, timer];
872
+ var GlobalContext;
944
873
 
945
- this._throttlers.push(throttler);
874
+ /* global self */
875
+ if (typeof self === 'object') {
876
+ GlobalContext = self;
946
877
 
947
- return throttler;
948
- },
878
+ /* global global */
879
+ } else if (typeof global === 'object') {
880
+ GlobalContext = global;
949
881
 
950
- debounce: function (target, method /* , args, wait, [immediate] */) {
951
- var backburner = this;
952
- var args = new Array(arguments.length);
953
- for (var i = 0; i < arguments.length; i++) {
954
- args[i] = arguments[i];
882
+ /* global window */
883
+ } else if (typeof window === 'object') {
884
+ GlobalContext = window;
885
+ } else {
886
+ throw new Error('no global: `self`, `global` nor `window` was found');
955
887
  }
956
888
 
957
- var immediate = args.pop();
958
- var wait, index, debouncee, timer;
889
+ exports.default = GlobalContext;
890
+ });
891
+ enifed('backburner/queue', ['exports', 'backburner/utils'], function (exports, _backburnerUtils) {
892
+ 'use strict';
959
893
 
960
- if (_backburnerUtils.isNumber(immediate) || _backburnerUtils.isString(immediate)) {
961
- wait = immediate;
962
- immediate = false;
963
- } else {
964
- wait = args.pop();
965
- }
894
+ exports.default = Queue;
966
895
 
967
- wait = parseInt(wait, 10);
968
- // Remove debouncee
969
- index = findDebouncee(target, method, this._debouncees);
896
+ function Queue(name, options, globalOptions) {
897
+ this.name = name;
898
+ this.globalOptions = globalOptions || {};
899
+ this.options = options;
900
+ this._queue = [];
901
+ this.targetQueues = {};
902
+ this._queueBeingFlushed = undefined;
903
+ }
970
904
 
971
- if (index > -1) {
972
- debouncee = this._debouncees[index];
973
- this._debouncees.splice(index, 1);
974
- this._platform.clearTimeout(debouncee[2]);
975
- }
905
+ Queue.prototype = {
906
+ push: function (target, method, args, stack) {
907
+ var queue = this._queue;
908
+ queue.push(target, method, args, stack);
976
909
 
977
- timer = this._platform.setTimeout(function () {
978
- if (!immediate) {
979
- backburner.run.apply(backburner, args);
980
- }
981
- var index = findDebouncee(target, method, backburner._debouncees);
982
- if (index > -1) {
983
- backburner._debouncees.splice(index, 1);
984
- }
985
- }, wait);
986
-
987
- if (immediate && index === -1) {
988
- backburner.run.apply(backburner, args);
989
- }
990
-
991
- debouncee = [target, method, timer];
992
-
993
- backburner._debouncees.push(debouncee);
994
-
995
- return debouncee;
910
+ return {
911
+ queue: this,
912
+ target: target,
913
+ method: method
914
+ };
996
915
  },
997
916
 
998
- cancelTimers: function () {
999
- _backburnerUtils.each(this._throttlers, this._boundClearItems);
1000
- this._throttlers = [];
1001
-
1002
- _backburnerUtils.each(this._debouncees, this._boundClearItems);
1003
- this._debouncees = [];
917
+ pushUniqueWithoutGuid: function (target, method, args, stack) {
918
+ var queue = this._queue;
1004
919
 
1005
- this._clearTimerTimeout();
1006
- this._timers = [];
920
+ for (var i = 0, l = queue.length; i < l; i += 4) {
921
+ var currentTarget = queue[i];
922
+ var currentMethod = queue[i + 1];
1007
923
 
1008
- if (this._autorun) {
1009
- this._platform.clearTimeout(this._autorun);
1010
- this._autorun = null;
924
+ if (currentTarget === target && currentMethod === method) {
925
+ queue[i + 2] = args; // replace args
926
+ queue[i + 3] = stack; // replace stack
927
+ return;
928
+ }
1011
929
  }
1012
- },
1013
930
 
1014
- hasTimers: function () {
1015
- return !!this._timers.length || !!this._debouncees.length || !!this._throttlers.length || this._autorun;
931
+ queue.push(target, method, args, stack);
1016
932
  },
1017
933
 
1018
- cancel: function (timer) {
1019
- var timerType = typeof timer;
934
+ targetQueue: function (targetQueue, target, method, args, stack) {
935
+ var queue = this._queue;
1020
936
 
1021
- if (timer && timerType === 'object' && timer.queue && timer.method) {
1022
- // we're cancelling a deferOnce
1023
- return timer.queue.cancel(timer);
1024
- } else if (timerType === 'function') {
1025
- // we're cancelling a setTimeout
1026
- for (var i = 0, l = this._timers.length; i < l; i += 2) {
1027
- if (this._timers[i + 1] === timer) {
1028
- this._timers.splice(i, 2); // remove the two elements
1029
- if (i === 0) {
1030
- this._reinstallTimerTimeout();
1031
- }
1032
- return true;
1033
- }
937
+ for (var i = 0, l = targetQueue.length; i < l; i += 2) {
938
+ var currentMethod = targetQueue[i];
939
+ var currentIndex = targetQueue[i + 1];
940
+
941
+ if (currentMethod === method) {
942
+ queue[currentIndex + 2] = args; // replace args
943
+ queue[currentIndex + 3] = stack; // replace stack
944
+ return;
1034
945
  }
1035
- } else if (Object.prototype.toString.call(timer) === '[object Array]') {
1036
- // we're cancelling a throttle or debounce
1037
- return this._cancelItem(findThrottler, this._throttlers, timer) || this._cancelItem(findDebouncee, this._debouncees, timer);
1038
- } else {
1039
- return; // timer was null or not a timer
1040
946
  }
947
+
948
+ targetQueue.push(method, queue.push(target, method, args, stack) - 4);
1041
949
  },
1042
950
 
1043
- _cancelItem: function (findMethod, array, timer) {
1044
- var item, index;
951
+ pushUniqueWithGuid: function (guid, target, method, args, stack) {
952
+ var hasLocalQueue = this.targetQueues[guid];
1045
953
 
1046
- if (timer.length < 3) {
1047
- return false;
954
+ if (hasLocalQueue) {
955
+ this.targetQueue(hasLocalQueue, target, method, args, stack);
956
+ } else {
957
+ this.targetQueues[guid] = [method, this._queue.push(target, method, args, stack) - 4];
1048
958
  }
1049
959
 
1050
- index = findMethod(timer[0], timer[1], array);
1051
-
1052
- if (index > -1) {
960
+ return {
961
+ queue: this,
962
+ target: target,
963
+ method: method
964
+ };
965
+ },
1053
966
 
1054
- item = array[index];
967
+ pushUnique: function (target, method, args, stack) {
968
+ var KEY = this.globalOptions.GUID_KEY;
1055
969
 
1056
- if (item[2] === timer[2]) {
1057
- array.splice(index, 1);
1058
- this._platform.clearTimeout(timer[2]);
1059
- return true;
970
+ if (target && KEY) {
971
+ var guid = target[KEY];
972
+ if (guid) {
973
+ return this.pushUniqueWithGuid(guid, target, method, args, stack);
1060
974
  }
1061
975
  }
1062
976
 
1063
- return false;
977
+ this.pushUniqueWithoutGuid(target, method, args, stack);
978
+
979
+ return {
980
+ queue: this,
981
+ target: target,
982
+ method: method
983
+ };
1064
984
  },
1065
985
 
1066
- _runExpiredTimers: function () {
1067
- this._timerTimeoutId = undefined;
1068
- this.run(this, this._scheduleExpiredTimers);
986
+ invoke: function (target, method, args, _, _errorRecordedForStack) {
987
+ if (args && args.length > 0) {
988
+ method.apply(target, args);
989
+ } else {
990
+ method.call(target);
991
+ }
1069
992
  },
1070
993
 
1071
- _scheduleExpiredTimers: function () {
1072
- var n = Date.now();
1073
- var timers = this._timers;
1074
- var i = 0;
1075
- var l = timers.length;
1076
- for (; i < l; i += 2) {
1077
- var executeAt = timers[i];
1078
- var fn = timers[i + 1];
1079
- if (executeAt <= n) {
1080
- this.schedule(this.options.defaultQueue, null, fn);
994
+ invokeWithOnError: function (target, method, args, onError, errorRecordedForStack) {
995
+ try {
996
+ if (args && args.length > 0) {
997
+ method.apply(target, args);
1081
998
  } else {
1082
- break;
999
+ method.call(target);
1083
1000
  }
1001
+ } catch (error) {
1002
+ onError(error, errorRecordedForStack);
1084
1003
  }
1085
- timers.splice(0, i);
1086
- this._installTimerTimeout();
1087
- },
1088
-
1089
- _reinstallTimerTimeout: function () {
1090
- this._clearTimerTimeout();
1091
- this._installTimerTimeout();
1092
1004
  },
1093
1005
 
1094
- _clearTimerTimeout: function () {
1095
- if (!this._timerTimeoutId) {
1096
- return;
1097
- }
1098
- this._platform.clearTimeout(this._timerTimeoutId);
1099
- this._timerTimeoutId = undefined;
1100
- },
1006
+ flush: function (sync) {
1007
+ var queue = this._queue;
1008
+ var length = queue.length;
1101
1009
 
1102
- _installTimerTimeout: function () {
1103
- if (!this._timers.length) {
1010
+ if (length === 0) {
1104
1011
  return;
1105
1012
  }
1106
- var minExpiresAt = this._timers[0];
1107
- var n = Date.now();
1108
- var wait = Math.max(0, minExpiresAt - n);
1109
- this._timerTimeoutId = this._platform.setTimeout(this._boundRunExpiredTimers, wait);
1110
- }
1111
- };
1112
-
1113
- Backburner.prototype.schedule = Backburner.prototype.defer;
1114
- Backburner.prototype.scheduleOnce = Backburner.prototype.deferOnce;
1115
- Backburner.prototype.later = Backburner.prototype.setTimeout;
1116
1013
 
1117
- function getOnError(options) {
1118
- return options.onError || options.onErrorTarget && options.onErrorTarget[options.onErrorMethod];
1119
- }
1014
+ var globalOptions = this.globalOptions;
1015
+ var options = this.options;
1016
+ var before = options && options.before;
1017
+ var after = options && options.after;
1018
+ var onError = globalOptions.onError || globalOptions.onErrorTarget && globalOptions.onErrorTarget[globalOptions.onErrorMethod];
1019
+ var target, method, args, errorRecordedForStack;
1020
+ var invoke = onError ? this.invokeWithOnError : this.invoke;
1120
1021
 
1121
- function createAutorun(backburner) {
1122
- backburner.begin();
1123
- backburner._autorun = backburner._platform.setTimeout(function () {
1124
- backburner._autorun = null;
1125
- backburner.end();
1126
- });
1127
- }
1022
+ this.targetQueues = Object.create(null);
1023
+ var queueItems = this._queueBeingFlushed = this._queue.slice();
1024
+ this._queue = [];
1128
1025
 
1129
- function findDebouncee(target, method, debouncees) {
1130
- return findItem(target, method, debouncees);
1131
- }
1026
+ if (before) {
1027
+ before();
1028
+ }
1132
1029
 
1133
- function findThrottler(target, method, throttlers) {
1134
- return findItem(target, method, throttlers);
1135
- }
1030
+ for (var i = 0; i < length; i += 4) {
1031
+ target = queueItems[i];
1032
+ method = queueItems[i + 1];
1033
+ args = queueItems[i + 2];
1034
+ errorRecordedForStack = queueItems[i + 3]; // Debugging assistance
1136
1035
 
1137
- function findItem(target, method, collection) {
1138
- var item;
1139
- var index = -1;
1036
+ if (_backburnerUtils.isString(method)) {
1037
+ method = target[method];
1038
+ }
1140
1039
 
1141
- for (var i = 0, l = collection.length; i < l; i++) {
1142
- item = collection[i];
1143
- if (item[0] === target && item[1] === method) {
1144
- index = i;
1145
- break;
1040
+ // method could have been nullified / canceled during flush
1041
+ if (method) {
1042
+ //
1043
+ // ** Attention intrepid developer **
1044
+ //
1045
+ // To find out the stack of this task when it was scheduled onto
1046
+ // the run loop, add the following to your app.js:
1047
+ //
1048
+ // Ember.run.backburner.DEBUG = true; // NOTE: This slows your app, don't leave it on in production.
1049
+ //
1050
+ // Once that is in place, when you are at a breakpoint and navigate
1051
+ // here in the stack explorer, you can look at `errorRecordedForStack.stack`,
1052
+ // which will be the captured stack when this job was scheduled.
1053
+ //
1054
+ invoke(target, method, args, onError, errorRecordedForStack);
1055
+ }
1146
1056
  }
1147
- }
1148
1057
 
1149
- return index;
1150
- }
1058
+ if (after) {
1059
+ after();
1060
+ }
1151
1061
 
1152
- function clearItems(item) {
1153
- this._platform.clearTimeout(item[2]);
1154
- }
1155
- });
1156
- enifed('container/container', ['exports', 'ember-environment', 'ember-metal/debug', 'ember-metal/dictionary', 'container/owner', 'ember-runtime/mixins/container_proxy', 'ember-metal/symbol'], function (exports, _emberEnvironment, _emberMetalDebug, _emberMetalDictionary, _containerOwner, _emberRuntimeMixinsContainer_proxy, _emberMetalSymbol) {
1157
- 'use strict';
1062
+ this._queueBeingFlushed = undefined;
1158
1063
 
1159
- var CONTAINER_OVERRIDE = _emberMetalSymbol.default('CONTAINER_OVERRIDE');
1064
+ if (sync !== false && this._queue.length > 0) {
1065
+ // check if new items have been added
1066
+ this.flush(true);
1067
+ }
1068
+ },
1160
1069
 
1161
- /**
1070
+ cancel: function (actionToCancel) {
1071
+ var queue = this._queue,
1072
+ currentTarget,
1073
+ currentMethod,
1074
+ i,
1075
+ l;
1076
+ var target = actionToCancel.target;
1077
+ var method = actionToCancel.method;
1078
+ var GUID_KEY = this.globalOptions.GUID_KEY;
1079
+
1080
+ if (GUID_KEY && this.targetQueues && target) {
1081
+ var targetQueue = this.targetQueues[target[GUID_KEY]];
1082
+
1083
+ if (targetQueue) {
1084
+ for (i = 0, l = targetQueue.length; i < l; i++) {
1085
+ if (targetQueue[i] === method) {
1086
+ targetQueue.splice(i, 1);
1087
+ }
1088
+ }
1089
+ }
1090
+ }
1091
+
1092
+ for (i = 0, l = queue.length; i < l; i += 4) {
1093
+ currentTarget = queue[i];
1094
+ currentMethod = queue[i + 1];
1095
+
1096
+ if (currentTarget === target && currentMethod === method) {
1097
+ queue.splice(i, 4);
1098
+ return true;
1099
+ }
1100
+ }
1101
+
1102
+ // if not found in current queue
1103
+ // could be in the queue that is being flushed
1104
+ queue = this._queueBeingFlushed;
1105
+
1106
+ if (!queue) {
1107
+ return;
1108
+ }
1109
+
1110
+ for (i = 0, l = queue.length; i < l; i += 4) {
1111
+ currentTarget = queue[i];
1112
+ currentMethod = queue[i + 1];
1113
+
1114
+ if (currentTarget === target && currentMethod === method) {
1115
+ // don't mess with array during flush
1116
+ // just nullify the method
1117
+ queue[i + 1] = null;
1118
+ return true;
1119
+ }
1120
+ }
1121
+ }
1122
+ };
1123
+ });
1124
+ enifed('backburner/utils', ['exports'], function (exports) {
1125
+ 'use strict';
1126
+
1127
+ exports.each = each;
1128
+ exports.isString = isString;
1129
+ exports.isFunction = isFunction;
1130
+ exports.isNumber = isNumber;
1131
+ exports.isCoercableNumber = isCoercableNumber;
1132
+ var NUMBER = /\d+/;
1133
+
1134
+ function each(collection, callback) {
1135
+ for (var i = 0; i < collection.length; i++) {
1136
+ callback(collection[i]);
1137
+ }
1138
+ }
1139
+
1140
+ function isString(suspect) {
1141
+ return typeof suspect === 'string';
1142
+ }
1143
+
1144
+ function isFunction(suspect) {
1145
+ return typeof suspect === 'function';
1146
+ }
1147
+
1148
+ function isNumber(suspect) {
1149
+ return typeof suspect === 'number';
1150
+ }
1151
+
1152
+ function isCoercableNumber(number) {
1153
+ return isNumber(number) || NUMBER.test(number);
1154
+ }
1155
+ });
1156
+ enifed('container/container', ['exports', 'ember-environment', 'ember-metal/debug', 'ember-metal/dictionary', 'container/owner', 'ember-runtime/mixins/container_proxy', 'ember-metal/symbol'], function (exports, _emberEnvironment, _emberMetalDebug, _emberMetalDictionary, _containerOwner, _emberRuntimeMixinsContainer_proxy, _emberMetalSymbol) {
1157
+ 'use strict';
1158
+
1159
+ var CONTAINER_OVERRIDE = _emberMetalSymbol.default('CONTAINER_OVERRIDE');
1160
+
1161
+ /**
1162
1162
  A container used to instantiate and cache objects.
1163
1163
 
1164
1164
  Every `Container` must be associated with a `Registry`, which is referenced
@@ -2477,16 +2477,6 @@ enifed('container/registry', ['exports', 'ember-metal/debug', 'ember-metal/dicti
2477
2477
 
2478
2478
  exports.default = Registry;
2479
2479
  });
2480
- enifed("ember/features", ["exports"], function (exports) {
2481
- "use strict";
2482
-
2483
- exports.default = {};
2484
- });
2485
- enifed("ember/version", ["exports"], function (exports) {
2486
- "use strict";
2487
-
2488
- exports.default = "2.7.0-beta.3";
2489
- });
2490
2480
  enifed('ember-console/index', ['exports', 'ember-environment'], function (exports, _emberEnvironment) {
2491
2481
  'use strict';
2492
2482
 
@@ -4813,13 +4803,11 @@ enifed('ember-metal/events', ['exports', 'ember-metal/debug', 'ember-metal/utils
4813
4803
  function addListener(obj, eventName, target, method, once) {
4814
4804
  _emberMetalDebug.assert('You must pass at least an object and event name to Ember.addListener', !!obj && !!eventName);
4815
4805
 
4816
- if (eventName === 'didInitAttrs' && obj.isComponent) {
4817
- _emberMetalDebug.deprecate('[DEPRECATED] didInitAttrs called in ' + obj.toString() + '.', false, {
4818
- id: 'ember-views.did-init-attrs',
4819
- until: '3.0.0',
4820
- url: 'http://emberjs.com/deprecations/v2.x#toc_ember-component-didinitattrs'
4821
- });
4822
- }
4806
+ _emberMetalDebug.deprecate('didInitAttrs called in ' + (obj && obj.toString && obj.toString()) + '.', eventName !== 'didInitAttrs', {
4807
+ id: 'ember-views.did-init-attrs',
4808
+ until: '3.0.0',
4809
+ url: 'http://emberjs.com/deprecations/v2.x#toc_ember-component-didinitattrs'
4810
+ });
4823
4811
 
4824
4812
  if (!method && 'function' === typeof target) {
4825
4813
  method = target;
@@ -19719,6 +19707,103 @@ enifed('ember-runtime/utils', ['exports', 'ember-runtime/mixins/array', 'ember-r
19719
19707
  return ret;
19720
19708
  }
19721
19709
  });
19710
+ enifed("ember/features", ["exports"], function (exports) {
19711
+ "use strict";
19712
+
19713
+ exports.default = {};
19714
+ });
19715
+ enifed("ember/version", ["exports"], function (exports) {
19716
+ "use strict";
19717
+
19718
+ exports.default = "2.7.0-beta.4";
19719
+ });
19720
+ enifed('rsvp', ['exports', 'rsvp/promise', 'rsvp/events', 'rsvp/node', 'rsvp/all', 'rsvp/all-settled', 'rsvp/race', 'rsvp/hash', 'rsvp/hash-settled', 'rsvp/rethrow', 'rsvp/defer', 'rsvp/config', 'rsvp/map', 'rsvp/resolve', 'rsvp/reject', 'rsvp/filter', 'rsvp/asap'], function (exports, _rsvpPromise, _rsvpEvents, _rsvpNode, _rsvpAll, _rsvpAllSettled, _rsvpRace, _rsvpHash, _rsvpHashSettled, _rsvpRethrow, _rsvpDefer, _rsvpConfig, _rsvpMap, _rsvpResolve, _rsvpReject, _rsvpFilter, _rsvpAsap) {
19721
+ 'use strict';
19722
+
19723
+ // defaults
19724
+ _rsvpConfig.config.async = _rsvpAsap.default;
19725
+ _rsvpConfig.config.after = function (cb) {
19726
+ setTimeout(cb, 0);
19727
+ };
19728
+ var cast = _rsvpResolve.default;
19729
+ function async(callback, arg) {
19730
+ _rsvpConfig.config.async(callback, arg);
19731
+ }
19732
+
19733
+ function on() {
19734
+ _rsvpConfig.config['on'].apply(_rsvpConfig.config, arguments);
19735
+ }
19736
+
19737
+ function off() {
19738
+ _rsvpConfig.config['off'].apply(_rsvpConfig.config, arguments);
19739
+ }
19740
+
19741
+ // Set up instrumentation through `window.__PROMISE_INTRUMENTATION__`
19742
+ if (typeof window !== 'undefined' && typeof window['__PROMISE_INSTRUMENTATION__'] === 'object') {
19743
+ var callbacks = window['__PROMISE_INSTRUMENTATION__'];
19744
+ _rsvpConfig.configure('instrument', true);
19745
+ for (var eventName in callbacks) {
19746
+ if (callbacks.hasOwnProperty(eventName)) {
19747
+ on(eventName, callbacks[eventName]);
19748
+ }
19749
+ }
19750
+ }
19751
+
19752
+ exports.cast = cast;
19753
+ exports.Promise = _rsvpPromise.default;
19754
+ exports.EventTarget = _rsvpEvents.default;
19755
+ exports.all = _rsvpAll.default;
19756
+ exports.allSettled = _rsvpAllSettled.default;
19757
+ exports.race = _rsvpRace.default;
19758
+ exports.hash = _rsvpHash.default;
19759
+ exports.hashSettled = _rsvpHashSettled.default;
19760
+ exports.rethrow = _rsvpRethrow.default;
19761
+ exports.defer = _rsvpDefer.default;
19762
+ exports.denodeify = _rsvpNode.default;
19763
+ exports.configure = _rsvpConfig.configure;
19764
+ exports.on = on;
19765
+ exports.off = off;
19766
+ exports.resolve = _rsvpResolve.default;
19767
+ exports.reject = _rsvpReject.default;
19768
+ exports.async = async;
19769
+ exports.map = _rsvpMap.default;
19770
+ exports.filter = _rsvpFilter.default;
19771
+ });
19772
+ enifed('rsvp.umd', ['exports', 'rsvp/platform', 'rsvp'], function (exports, _rsvpPlatform, _rsvp) {
19773
+ 'use strict';
19774
+
19775
+ var RSVP = {
19776
+ 'race': _rsvp.race,
19777
+ 'Promise': _rsvp.Promise,
19778
+ 'allSettled': _rsvp.allSettled,
19779
+ 'hash': _rsvp.hash,
19780
+ 'hashSettled': _rsvp.hashSettled,
19781
+ 'denodeify': _rsvp.denodeify,
19782
+ 'on': _rsvp.on,
19783
+ 'off': _rsvp.off,
19784
+ 'map': _rsvp.map,
19785
+ 'filter': _rsvp.filter,
19786
+ 'resolve': _rsvp.resolve,
19787
+ 'reject': _rsvp.reject,
19788
+ 'all': _rsvp.all,
19789
+ 'rethrow': _rsvp.rethrow,
19790
+ 'defer': _rsvp.defer,
19791
+ 'EventTarget': _rsvp.EventTarget,
19792
+ 'configure': _rsvp.configure,
19793
+ 'async': _rsvp.async
19794
+ };
19795
+
19796
+ /* global define:true module:true window: true */
19797
+ if (typeof define === 'function' && define['amd']) {
19798
+ define(function () {
19799
+ return RSVP;
19800
+ });
19801
+ } else if (typeof module !== 'undefined' && module['exports']) {
19802
+ module['exports'] = RSVP;
19803
+ } else if (typeof _rsvpPlatform.default !== 'undefined') {
19804
+ _rsvpPlatform.default['RSVP'] = RSVP;
19805
+ }
19806
+ });
19722
19807
  enifed('rsvp/-internal', ['exports', 'rsvp/utils', 'rsvp/instrument', 'rsvp/config'], function (exports, _rsvpUtils, _rsvpInstrument, _rsvpConfig) {
19723
19808
  'use strict';
19724
19809
 
@@ -21368,271 +21453,14 @@ enifed('rsvp/platform', ['exports'], function (exports) {
21368
21453
 
21369
21454
  exports.default = platform;
21370
21455
  });
21371
- enifed('rsvp/promise/all', ['exports', 'rsvp/enumerator'], function (exports, _rsvpEnumerator) {
21456
+ enifed('rsvp/promise-hash', ['exports', 'rsvp/enumerator', 'rsvp/-internal', 'rsvp/utils'], function (exports, _rsvpEnumerator, _rsvpInternal, _rsvpUtils) {
21372
21457
  'use strict';
21373
21458
 
21374
- exports.default = all;
21459
+ function PromiseHash(Constructor, object, label) {
21460
+ this._superConstructor(Constructor, object, true, label);
21461
+ }
21375
21462
 
21376
- /**
21377
- `RSVP.Promise.all` accepts an array of promises, and returns a new promise which
21378
- is fulfilled with an array of fulfillment values for the passed promises, or
21379
- rejected with the reason of the first passed promise to be rejected. It casts all
21380
- elements of the passed iterable to promises as it runs this algorithm.
21381
-
21382
- Example:
21383
-
21384
- ```javascript
21385
- var promise1 = RSVP.resolve(1);
21386
- var promise2 = RSVP.resolve(2);
21387
- var promise3 = RSVP.resolve(3);
21388
- var promises = [ promise1, promise2, promise3 ];
21389
-
21390
- RSVP.Promise.all(promises).then(function(array){
21391
- // The array here would be [ 1, 2, 3 ];
21392
- });
21393
- ```
21394
-
21395
- If any of the `promises` given to `RSVP.all` are rejected, the first promise
21396
- that is rejected will be given as an argument to the returned promises's
21397
- rejection handler. For example:
21398
-
21399
- Example:
21400
-
21401
- ```javascript
21402
- var promise1 = RSVP.resolve(1);
21403
- var promise2 = RSVP.reject(new Error("2"));
21404
- var promise3 = RSVP.reject(new Error("3"));
21405
- var promises = [ promise1, promise2, promise3 ];
21406
-
21407
- RSVP.Promise.all(promises).then(function(array){
21408
- // Code here never runs because there are rejected promises!
21409
- }, function(error) {
21410
- // error.message === "2"
21411
- });
21412
- ```
21413
-
21414
- @method all
21415
- @static
21416
- @param {Array} entries array of promises
21417
- @param {String} label optional string for labeling the promise.
21418
- Useful for tooling.
21419
- @return {Promise} promise that is fulfilled when all `promises` have been
21420
- fulfilled, or rejected if any of them become rejected.
21421
- @static
21422
- */
21423
-
21424
- function all(entries, label) {
21425
- return new _rsvpEnumerator.default(this, entries, true, /* abort on reject */label).promise;
21426
- }
21427
- });
21428
- enifed('rsvp/promise/race', ['exports', 'rsvp/utils', 'rsvp/-internal'], function (exports, _rsvpUtils, _rsvpInternal) {
21429
- 'use strict';
21430
-
21431
- exports.default = race;
21432
-
21433
- /**
21434
- `RSVP.Promise.race` returns a new promise which is settled in the same way as the
21435
- first passed promise to settle.
21436
-
21437
- Example:
21438
-
21439
- ```javascript
21440
- var promise1 = new RSVP.Promise(function(resolve, reject){
21441
- setTimeout(function(){
21442
- resolve('promise 1');
21443
- }, 200);
21444
- });
21445
-
21446
- var promise2 = new RSVP.Promise(function(resolve, reject){
21447
- setTimeout(function(){
21448
- resolve('promise 2');
21449
- }, 100);
21450
- });
21451
-
21452
- RSVP.Promise.race([promise1, promise2]).then(function(result){
21453
- // result === 'promise 2' because it was resolved before promise1
21454
- // was resolved.
21455
- });
21456
- ```
21457
-
21458
- `RSVP.Promise.race` is deterministic in that only the state of the first
21459
- settled promise matters. For example, even if other promises given to the
21460
- `promises` array argument are resolved, but the first settled promise has
21461
- become rejected before the other promises became fulfilled, the returned
21462
- promise will become rejected:
21463
-
21464
- ```javascript
21465
- var promise1 = new RSVP.Promise(function(resolve, reject){
21466
- setTimeout(function(){
21467
- resolve('promise 1');
21468
- }, 200);
21469
- });
21470
-
21471
- var promise2 = new RSVP.Promise(function(resolve, reject){
21472
- setTimeout(function(){
21473
- reject(new Error('promise 2'));
21474
- }, 100);
21475
- });
21476
-
21477
- RSVP.Promise.race([promise1, promise2]).then(function(result){
21478
- // Code here never runs
21479
- }, function(reason){
21480
- // reason.message === 'promise 2' because promise 2 became rejected before
21481
- // promise 1 became fulfilled
21482
- });
21483
- ```
21484
-
21485
- An example real-world use case is implementing timeouts:
21486
-
21487
- ```javascript
21488
- RSVP.Promise.race([ajax('foo.json'), timeout(5000)])
21489
- ```
21490
-
21491
- @method race
21492
- @static
21493
- @param {Array} entries array of promises to observe
21494
- @param {String} label optional string for describing the promise returned.
21495
- Useful for tooling.
21496
- @return {Promise} a promise which settles in the same way as the first passed
21497
- promise to settle.
21498
- */
21499
-
21500
- function race(entries, label) {
21501
- /*jshint validthis:true */
21502
- var Constructor = this;
21503
-
21504
- var promise = new Constructor(_rsvpInternal.noop, label);
21505
-
21506
- if (!_rsvpUtils.isArray(entries)) {
21507
- _rsvpInternal.reject(promise, new TypeError('You must pass an array to race.'));
21508
- return promise;
21509
- }
21510
-
21511
- var length = entries.length;
21512
-
21513
- function onFulfillment(value) {
21514
- _rsvpInternal.resolve(promise, value);
21515
- }
21516
-
21517
- function onRejection(reason) {
21518
- _rsvpInternal.reject(promise, reason);
21519
- }
21520
-
21521
- for (var i = 0; promise._state === _rsvpInternal.PENDING && i < length; i++) {
21522
- _rsvpInternal.subscribe(Constructor.resolve(entries[i]), undefined, onFulfillment, onRejection);
21523
- }
21524
-
21525
- return promise;
21526
- }
21527
- });
21528
- enifed('rsvp/promise/reject', ['exports', 'rsvp/-internal'], function (exports, _rsvpInternal) {
21529
- 'use strict';
21530
-
21531
- exports.default = reject;
21532
-
21533
- /**
21534
- `RSVP.Promise.reject` returns a promise rejected with the passed `reason`.
21535
- It is shorthand for the following:
21536
-
21537
- ```javascript
21538
- var promise = new RSVP.Promise(function(resolve, reject){
21539
- reject(new Error('WHOOPS'));
21540
- });
21541
-
21542
- promise.then(function(value){
21543
- // Code here doesn't run because the promise is rejected!
21544
- }, function(reason){
21545
- // reason.message === 'WHOOPS'
21546
- });
21547
- ```
21548
-
21549
- Instead of writing the above, your code now simply becomes the following:
21550
-
21551
- ```javascript
21552
- var promise = RSVP.Promise.reject(new Error('WHOOPS'));
21553
-
21554
- promise.then(function(value){
21555
- // Code here doesn't run because the promise is rejected!
21556
- }, function(reason){
21557
- // reason.message === 'WHOOPS'
21558
- });
21559
- ```
21560
-
21561
- @method reject
21562
- @static
21563
- @param {*} reason value that the returned promise will be rejected with.
21564
- @param {String} label optional string for identifying the returned promise.
21565
- Useful for tooling.
21566
- @return {Promise} a promise rejected with the given `reason`.
21567
- */
21568
-
21569
- function reject(reason, label) {
21570
- /*jshint validthis:true */
21571
- var Constructor = this;
21572
- var promise = new Constructor(_rsvpInternal.noop, label);
21573
- _rsvpInternal.reject(promise, reason);
21574
- return promise;
21575
- }
21576
- });
21577
- enifed('rsvp/promise/resolve', ['exports', 'rsvp/-internal'], function (exports, _rsvpInternal) {
21578
- 'use strict';
21579
-
21580
- exports.default = resolve;
21581
-
21582
- /**
21583
- `RSVP.Promise.resolve` returns a promise that will become resolved with the
21584
- passed `value`. It is shorthand for the following:
21585
-
21586
- ```javascript
21587
- var promise = new RSVP.Promise(function(resolve, reject){
21588
- resolve(1);
21589
- });
21590
-
21591
- promise.then(function(value){
21592
- // value === 1
21593
- });
21594
- ```
21595
-
21596
- Instead of writing the above, your code now simply becomes the following:
21597
-
21598
- ```javascript
21599
- var promise = RSVP.Promise.resolve(1);
21600
-
21601
- promise.then(function(value){
21602
- // value === 1
21603
- });
21604
- ```
21605
-
21606
- @method resolve
21607
- @static
21608
- @param {*} object value that the returned promise will be resolved with
21609
- @param {String} label optional string for identifying the returned promise.
21610
- Useful for tooling.
21611
- @return {Promise} a promise that will become fulfilled with the given
21612
- `value`
21613
- */
21614
-
21615
- function resolve(object, label) {
21616
- /*jshint validthis:true */
21617
- var Constructor = this;
21618
-
21619
- if (object && typeof object === 'object' && object.constructor === Constructor) {
21620
- return object;
21621
- }
21622
-
21623
- var promise = new Constructor(_rsvpInternal.noop, label);
21624
- _rsvpInternal.resolve(promise, object);
21625
- return promise;
21626
- }
21627
- });
21628
- enifed('rsvp/promise-hash', ['exports', 'rsvp/enumerator', 'rsvp/-internal', 'rsvp/utils'], function (exports, _rsvpEnumerator, _rsvpInternal, _rsvpUtils) {
21629
- 'use strict';
21630
-
21631
- function PromiseHash(Constructor, object, label) {
21632
- this._superConstructor(Constructor, object, true, label);
21633
- }
21634
-
21635
- exports.default = PromiseHash;
21463
+ exports.default = PromiseHash;
21636
21464
 
21637
21465
  PromiseHash.prototype = _rsvpUtils.o_create(_rsvpEnumerator.default.prototype);
21638
21466
  PromiseHash.prototype._superConstructor = _rsvpEnumerator.default;
@@ -22054,105 +21882,362 @@ enifed('rsvp/promise', ['exports', 'rsvp/config', 'rsvp/instrument', 'rsvp/utils
22054
21882
  _rsvpInstrument.default('chained', parent, child);
22055
21883
  }
22056
21884
 
22057
- if (state) {
22058
- var callback = arguments[state - 1];
22059
- _rsvpConfig.config.async(function () {
22060
- _rsvpInternal.invokeCallback(state, child, callback, result);
22061
- });
22062
- } else {
22063
- _rsvpInternal.subscribe(parent, child, onFulfillment, onRejection);
22064
- }
21885
+ if (state) {
21886
+ var callback = arguments[state - 1];
21887
+ _rsvpConfig.config.async(function () {
21888
+ _rsvpInternal.invokeCallback(state, child, callback, result);
21889
+ });
21890
+ } else {
21891
+ _rsvpInternal.subscribe(parent, child, onFulfillment, onRejection);
21892
+ }
21893
+
21894
+ return child;
21895
+ },
21896
+
21897
+ /**
21898
+ `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
21899
+ as the catch block of a try/catch statement.
21900
+
21901
+ ```js
21902
+ function findAuthor(){
21903
+ throw new Error('couldn't find that author');
21904
+ }
21905
+
21906
+ // synchronous
21907
+ try {
21908
+ findAuthor();
21909
+ } catch(reason) {
21910
+ // something went wrong
21911
+ }
21912
+
21913
+ // async with promises
21914
+ findAuthor().catch(function(reason){
21915
+ // something went wrong
21916
+ });
21917
+ ```
21918
+
21919
+ @method catch
21920
+ @param {Function} onRejection
21921
+ @param {String} label optional string for labeling the promise.
21922
+ Useful for tooling.
21923
+ @return {Promise}
21924
+ */
21925
+ 'catch': function (onRejection, label) {
21926
+ return this.then(undefined, onRejection, label);
21927
+ },
21928
+
21929
+ /**
21930
+ `finally` will be invoked regardless of the promise's fate just as native
21931
+ try/catch/finally behaves
21932
+
21933
+ Synchronous example:
21934
+
21935
+ ```js
21936
+ findAuthor() {
21937
+ if (Math.random() > 0.5) {
21938
+ throw new Error();
21939
+ }
21940
+ return new Author();
21941
+ }
21942
+
21943
+ try {
21944
+ return findAuthor(); // succeed or fail
21945
+ } catch(error) {
21946
+ return findOtherAuther();
21947
+ } finally {
21948
+ // always runs
21949
+ // doesn't affect the return value
21950
+ }
21951
+ ```
21952
+
21953
+ Asynchronous example:
21954
+
21955
+ ```js
21956
+ findAuthor().catch(function(reason){
21957
+ return findOtherAuther();
21958
+ }).finally(function(){
21959
+ // author was either found, or not
21960
+ });
21961
+ ```
21962
+
21963
+ @method finally
21964
+ @param {Function} callback
21965
+ @param {String} label optional string for labeling the promise.
21966
+ Useful for tooling.
21967
+ @return {Promise}
21968
+ */
21969
+ 'finally': function (callback, label) {
21970
+ var promise = this;
21971
+ var constructor = promise.constructor;
21972
+
21973
+ return promise.then(function (value) {
21974
+ return constructor.resolve(callback()).then(function () {
21975
+ return value;
21976
+ });
21977
+ }, function (reason) {
21978
+ return constructor.resolve(callback()).then(function () {
21979
+ throw reason;
21980
+ });
21981
+ }, label);
21982
+ }
21983
+ };
21984
+ });
21985
+ enifed('rsvp/promise/all', ['exports', 'rsvp/enumerator'], function (exports, _rsvpEnumerator) {
21986
+ 'use strict';
21987
+
21988
+ exports.default = all;
21989
+
21990
+ /**
21991
+ `RSVP.Promise.all` accepts an array of promises, and returns a new promise which
21992
+ is fulfilled with an array of fulfillment values for the passed promises, or
21993
+ rejected with the reason of the first passed promise to be rejected. It casts all
21994
+ elements of the passed iterable to promises as it runs this algorithm.
21995
+
21996
+ Example:
21997
+
21998
+ ```javascript
21999
+ var promise1 = RSVP.resolve(1);
22000
+ var promise2 = RSVP.resolve(2);
22001
+ var promise3 = RSVP.resolve(3);
22002
+ var promises = [ promise1, promise2, promise3 ];
22003
+
22004
+ RSVP.Promise.all(promises).then(function(array){
22005
+ // The array here would be [ 1, 2, 3 ];
22006
+ });
22007
+ ```
22008
+
22009
+ If any of the `promises` given to `RSVP.all` are rejected, the first promise
22010
+ that is rejected will be given as an argument to the returned promises's
22011
+ rejection handler. For example:
22012
+
22013
+ Example:
22014
+
22015
+ ```javascript
22016
+ var promise1 = RSVP.resolve(1);
22017
+ var promise2 = RSVP.reject(new Error("2"));
22018
+ var promise3 = RSVP.reject(new Error("3"));
22019
+ var promises = [ promise1, promise2, promise3 ];
22020
+
22021
+ RSVP.Promise.all(promises).then(function(array){
22022
+ // Code here never runs because there are rejected promises!
22023
+ }, function(error) {
22024
+ // error.message === "2"
22025
+ });
22026
+ ```
22027
+
22028
+ @method all
22029
+ @static
22030
+ @param {Array} entries array of promises
22031
+ @param {String} label optional string for labeling the promise.
22032
+ Useful for tooling.
22033
+ @return {Promise} promise that is fulfilled when all `promises` have been
22034
+ fulfilled, or rejected if any of them become rejected.
22035
+ @static
22036
+ */
22037
+
22038
+ function all(entries, label) {
22039
+ return new _rsvpEnumerator.default(this, entries, true, /* abort on reject */label).promise;
22040
+ }
22041
+ });
22042
+ enifed('rsvp/promise/race', ['exports', 'rsvp/utils', 'rsvp/-internal'], function (exports, _rsvpUtils, _rsvpInternal) {
22043
+ 'use strict';
22044
+
22045
+ exports.default = race;
22046
+
22047
+ /**
22048
+ `RSVP.Promise.race` returns a new promise which is settled in the same way as the
22049
+ first passed promise to settle.
22050
+
22051
+ Example:
22052
+
22053
+ ```javascript
22054
+ var promise1 = new RSVP.Promise(function(resolve, reject){
22055
+ setTimeout(function(){
22056
+ resolve('promise 1');
22057
+ }, 200);
22058
+ });
22059
+
22060
+ var promise2 = new RSVP.Promise(function(resolve, reject){
22061
+ setTimeout(function(){
22062
+ resolve('promise 2');
22063
+ }, 100);
22064
+ });
22065
+
22066
+ RSVP.Promise.race([promise1, promise2]).then(function(result){
22067
+ // result === 'promise 2' because it was resolved before promise1
22068
+ // was resolved.
22069
+ });
22070
+ ```
22071
+
22072
+ `RSVP.Promise.race` is deterministic in that only the state of the first
22073
+ settled promise matters. For example, even if other promises given to the
22074
+ `promises` array argument are resolved, but the first settled promise has
22075
+ become rejected before the other promises became fulfilled, the returned
22076
+ promise will become rejected:
22077
+
22078
+ ```javascript
22079
+ var promise1 = new RSVP.Promise(function(resolve, reject){
22080
+ setTimeout(function(){
22081
+ resolve('promise 1');
22082
+ }, 200);
22083
+ });
22084
+
22085
+ var promise2 = new RSVP.Promise(function(resolve, reject){
22086
+ setTimeout(function(){
22087
+ reject(new Error('promise 2'));
22088
+ }, 100);
22089
+ });
22090
+
22091
+ RSVP.Promise.race([promise1, promise2]).then(function(result){
22092
+ // Code here never runs
22093
+ }, function(reason){
22094
+ // reason.message === 'promise 2' because promise 2 became rejected before
22095
+ // promise 1 became fulfilled
22096
+ });
22097
+ ```
22098
+
22099
+ An example real-world use case is implementing timeouts:
22100
+
22101
+ ```javascript
22102
+ RSVP.Promise.race([ajax('foo.json'), timeout(5000)])
22103
+ ```
22104
+
22105
+ @method race
22106
+ @static
22107
+ @param {Array} entries array of promises to observe
22108
+ @param {String} label optional string for describing the promise returned.
22109
+ Useful for tooling.
22110
+ @return {Promise} a promise which settles in the same way as the first passed
22111
+ promise to settle.
22112
+ */
22113
+
22114
+ function race(entries, label) {
22115
+ /*jshint validthis:true */
22116
+ var Constructor = this;
22117
+
22118
+ var promise = new Constructor(_rsvpInternal.noop, label);
22119
+
22120
+ if (!_rsvpUtils.isArray(entries)) {
22121
+ _rsvpInternal.reject(promise, new TypeError('You must pass an array to race.'));
22122
+ return promise;
22123
+ }
22124
+
22125
+ var length = entries.length;
22126
+
22127
+ function onFulfillment(value) {
22128
+ _rsvpInternal.resolve(promise, value);
22129
+ }
22130
+
22131
+ function onRejection(reason) {
22132
+ _rsvpInternal.reject(promise, reason);
22133
+ }
22134
+
22135
+ for (var i = 0; promise._state === _rsvpInternal.PENDING && i < length; i++) {
22136
+ _rsvpInternal.subscribe(Constructor.resolve(entries[i]), undefined, onFulfillment, onRejection);
22137
+ }
22138
+
22139
+ return promise;
22140
+ }
22141
+ });
22142
+ enifed('rsvp/promise/reject', ['exports', 'rsvp/-internal'], function (exports, _rsvpInternal) {
22143
+ 'use strict';
22144
+
22145
+ exports.default = reject;
22146
+
22147
+ /**
22148
+ `RSVP.Promise.reject` returns a promise rejected with the passed `reason`.
22149
+ It is shorthand for the following:
22150
+
22151
+ ```javascript
22152
+ var promise = new RSVP.Promise(function(resolve, reject){
22153
+ reject(new Error('WHOOPS'));
22154
+ });
22155
+
22156
+ promise.then(function(value){
22157
+ // Code here doesn't run because the promise is rejected!
22158
+ }, function(reason){
22159
+ // reason.message === 'WHOOPS'
22160
+ });
22161
+ ```
22162
+
22163
+ Instead of writing the above, your code now simply becomes the following:
22164
+
22165
+ ```javascript
22166
+ var promise = RSVP.Promise.reject(new Error('WHOOPS'));
22167
+
22168
+ promise.then(function(value){
22169
+ // Code here doesn't run because the promise is rejected!
22170
+ }, function(reason){
22171
+ // reason.message === 'WHOOPS'
22172
+ });
22173
+ ```
22174
+
22175
+ @method reject
22176
+ @static
22177
+ @param {*} reason value that the returned promise will be rejected with.
22178
+ @param {String} label optional string for identifying the returned promise.
22179
+ Useful for tooling.
22180
+ @return {Promise} a promise rejected with the given `reason`.
22181
+ */
22182
+
22183
+ function reject(reason, label) {
22184
+ /*jshint validthis:true */
22185
+ var Constructor = this;
22186
+ var promise = new Constructor(_rsvpInternal.noop, label);
22187
+ _rsvpInternal.reject(promise, reason);
22188
+ return promise;
22189
+ }
22190
+ });
22191
+ enifed('rsvp/promise/resolve', ['exports', 'rsvp/-internal'], function (exports, _rsvpInternal) {
22192
+ 'use strict';
22065
22193
 
22066
- return child;
22067
- },
22194
+ exports.default = resolve;
22068
22195
 
22069
- /**
22070
- `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
22071
- as the catch block of a try/catch statement.
22072
-
22073
- ```js
22074
- function findAuthor(){
22075
- throw new Error('couldn't find that author');
22076
- }
22077
-
22078
- // synchronous
22079
- try {
22080
- findAuthor();
22081
- } catch(reason) {
22082
- // something went wrong
22083
- }
22084
-
22085
- // async with promises
22086
- findAuthor().catch(function(reason){
22087
- // something went wrong
22088
- });
22089
- ```
22090
-
22091
- @method catch
22092
- @param {Function} onRejection
22093
- @param {String} label optional string for labeling the promise.
22094
- Useful for tooling.
22095
- @return {Promise}
22096
- */
22097
- 'catch': function (onRejection, label) {
22098
- return this.then(undefined, onRejection, label);
22099
- },
22196
+ /**
22197
+ `RSVP.Promise.resolve` returns a promise that will become resolved with the
22198
+ passed `value`. It is shorthand for the following:
22199
+
22200
+ ```javascript
22201
+ var promise = new RSVP.Promise(function(resolve, reject){
22202
+ resolve(1);
22203
+ });
22204
+
22205
+ promise.then(function(value){
22206
+ // value === 1
22207
+ });
22208
+ ```
22209
+
22210
+ Instead of writing the above, your code now simply becomes the following:
22211
+
22212
+ ```javascript
22213
+ var promise = RSVP.Promise.resolve(1);
22214
+
22215
+ promise.then(function(value){
22216
+ // value === 1
22217
+ });
22218
+ ```
22219
+
22220
+ @method resolve
22221
+ @static
22222
+ @param {*} object value that the returned promise will be resolved with
22223
+ @param {String} label optional string for identifying the returned promise.
22224
+ Useful for tooling.
22225
+ @return {Promise} a promise that will become fulfilled with the given
22226
+ `value`
22227
+ */
22100
22228
 
22101
- /**
22102
- `finally` will be invoked regardless of the promise's fate just as native
22103
- try/catch/finally behaves
22104
-
22105
- Synchronous example:
22106
-
22107
- ```js
22108
- findAuthor() {
22109
- if (Math.random() > 0.5) {
22110
- throw new Error();
22111
- }
22112
- return new Author();
22113
- }
22114
-
22115
- try {
22116
- return findAuthor(); // succeed or fail
22117
- } catch(error) {
22118
- return findOtherAuther();
22119
- } finally {
22120
- // always runs
22121
- // doesn't affect the return value
22122
- }
22123
- ```
22124
-
22125
- Asynchronous example:
22126
-
22127
- ```js
22128
- findAuthor().catch(function(reason){
22129
- return findOtherAuther();
22130
- }).finally(function(){
22131
- // author was either found, or not
22132
- });
22133
- ```
22134
-
22135
- @method finally
22136
- @param {Function} callback
22137
- @param {String} label optional string for labeling the promise.
22138
- Useful for tooling.
22139
- @return {Promise}
22140
- */
22141
- 'finally': function (callback, label) {
22142
- var promise = this;
22143
- var constructor = promise.constructor;
22229
+ function resolve(object, label) {
22230
+ /*jshint validthis:true */
22231
+ var Constructor = this;
22144
22232
 
22145
- return promise.then(function (value) {
22146
- return constructor.resolve(callback()).then(function () {
22147
- return value;
22148
- });
22149
- }, function (reason) {
22150
- return constructor.resolve(callback()).then(function () {
22151
- throw reason;
22152
- });
22153
- }, label);
22233
+ if (object && typeof object === 'object' && object.constructor === Constructor) {
22234
+ return object;
22154
22235
  }
22155
- };
22236
+
22237
+ var promise = new Constructor(_rsvpInternal.noop, label);
22238
+ _rsvpInternal.resolve(promise, object);
22239
+ return promise;
22240
+ }
22156
22241
  });
22157
22242
  enifed('rsvp/race', ['exports', 'rsvp/promise'], function (exports, _rsvpPromise) {
22158
22243
  'use strict';
@@ -22321,93 +22406,6 @@ enifed('rsvp/utils', ['exports'], function (exports) {
22321
22406
  };
22322
22407
  exports.o_create = o_create;
22323
22408
  });
22324
- enifed('rsvp', ['exports', 'rsvp/promise', 'rsvp/events', 'rsvp/node', 'rsvp/all', 'rsvp/all-settled', 'rsvp/race', 'rsvp/hash', 'rsvp/hash-settled', 'rsvp/rethrow', 'rsvp/defer', 'rsvp/config', 'rsvp/map', 'rsvp/resolve', 'rsvp/reject', 'rsvp/filter', 'rsvp/asap'], function (exports, _rsvpPromise, _rsvpEvents, _rsvpNode, _rsvpAll, _rsvpAllSettled, _rsvpRace, _rsvpHash, _rsvpHashSettled, _rsvpRethrow, _rsvpDefer, _rsvpConfig, _rsvpMap, _rsvpResolve, _rsvpReject, _rsvpFilter, _rsvpAsap) {
22325
- 'use strict';
22326
-
22327
- // defaults
22328
- _rsvpConfig.config.async = _rsvpAsap.default;
22329
- _rsvpConfig.config.after = function (cb) {
22330
- setTimeout(cb, 0);
22331
- };
22332
- var cast = _rsvpResolve.default;
22333
- function async(callback, arg) {
22334
- _rsvpConfig.config.async(callback, arg);
22335
- }
22336
-
22337
- function on() {
22338
- _rsvpConfig.config['on'].apply(_rsvpConfig.config, arguments);
22339
- }
22340
-
22341
- function off() {
22342
- _rsvpConfig.config['off'].apply(_rsvpConfig.config, arguments);
22343
- }
22344
-
22345
- // Set up instrumentation through `window.__PROMISE_INTRUMENTATION__`
22346
- if (typeof window !== 'undefined' && typeof window['__PROMISE_INSTRUMENTATION__'] === 'object') {
22347
- var callbacks = window['__PROMISE_INSTRUMENTATION__'];
22348
- _rsvpConfig.configure('instrument', true);
22349
- for (var eventName in callbacks) {
22350
- if (callbacks.hasOwnProperty(eventName)) {
22351
- on(eventName, callbacks[eventName]);
22352
- }
22353
- }
22354
- }
22355
-
22356
- exports.cast = cast;
22357
- exports.Promise = _rsvpPromise.default;
22358
- exports.EventTarget = _rsvpEvents.default;
22359
- exports.all = _rsvpAll.default;
22360
- exports.allSettled = _rsvpAllSettled.default;
22361
- exports.race = _rsvpRace.default;
22362
- exports.hash = _rsvpHash.default;
22363
- exports.hashSettled = _rsvpHashSettled.default;
22364
- exports.rethrow = _rsvpRethrow.default;
22365
- exports.defer = _rsvpDefer.default;
22366
- exports.denodeify = _rsvpNode.default;
22367
- exports.configure = _rsvpConfig.configure;
22368
- exports.on = on;
22369
- exports.off = off;
22370
- exports.resolve = _rsvpResolve.default;
22371
- exports.reject = _rsvpReject.default;
22372
- exports.async = async;
22373
- exports.map = _rsvpMap.default;
22374
- exports.filter = _rsvpFilter.default;
22375
- });
22376
- enifed('rsvp.umd', ['exports', 'rsvp/platform', 'rsvp'], function (exports, _rsvpPlatform, _rsvp) {
22377
- 'use strict';
22378
-
22379
- var RSVP = {
22380
- 'race': _rsvp.race,
22381
- 'Promise': _rsvp.Promise,
22382
- 'allSettled': _rsvp.allSettled,
22383
- 'hash': _rsvp.hash,
22384
- 'hashSettled': _rsvp.hashSettled,
22385
- 'denodeify': _rsvp.denodeify,
22386
- 'on': _rsvp.on,
22387
- 'off': _rsvp.off,
22388
- 'map': _rsvp.map,
22389
- 'filter': _rsvp.filter,
22390
- 'resolve': _rsvp.resolve,
22391
- 'reject': _rsvp.reject,
22392
- 'all': _rsvp.all,
22393
- 'rethrow': _rsvp.rethrow,
22394
- 'defer': _rsvp.defer,
22395
- 'EventTarget': _rsvp.EventTarget,
22396
- 'configure': _rsvp.configure,
22397
- 'async': _rsvp.async
22398
- };
22399
-
22400
- /* global define:true module:true window: true */
22401
- if (typeof define === 'function' && define['amd']) {
22402
- define(function () {
22403
- return RSVP;
22404
- });
22405
- } else if (typeof module !== 'undefined' && module['exports']) {
22406
- module['exports'] = RSVP;
22407
- } else if (typeof _rsvpPlatform.default !== 'undefined') {
22408
- _rsvpPlatform.default['RSVP'] = RSVP;
22409
- }
22410
- });
22411
22409
  (function (m) { if (typeof module === "object" && module.exports) { module.exports = m } }(requireModule("ember-runtime").default));
22412
22410
 
22413
22411