rsvpjs-rails 3.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fa5f4f3f7a182a7f6eff7f06f7e874357f85b017
4
+ data.tar.gz: 90a619a16158ea3acb20772f41d2d5722d7eaa11
5
+ SHA512:
6
+ metadata.gz: 1fce9d53d0db71c1a09dfbba4cf41e33f82f2f8a63700c7bf1bc06005ae4fd0777a791d46457a3aaa6a1e412a93582716cbb53ebebbd22bbe8d9b80d07c0f13c
7
+ data.tar.gz: f0ddeddd8fd487d66d7c43e7b808f7d1f6b5d1c79dcb0b3388f2e6591ae99a4c44b68d0010222545cf6268226d2b6ddbf4b7b252162b0b8cc322003e1dd6de0f
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rsvpjs-rails.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Theodoros Orfanidis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ # rsvpjs-rails
2
+
3
+ This gem is a simple wrapper for the [RSVP.js](https://github.com/tildeio/rsvp.js)
4
+ library.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'rsvpjs-rails'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install rsvpjs-rails
19
+
20
+ ## Usage
21
+
22
+ Add the following directive to your Javascript manifest file:
23
+
24
+ //= require rsvp
25
+
26
+ Coffeescript flavor:
27
+
28
+ #= require rsvp
29
+
30
+ ## Versioning
31
+
32
+ rsvpjs-rails 3.0.11 == RSVP.js 3.0.11
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,8 @@
1
+ require "rsvpjs/rails/version"
2
+
3
+ module Rsvpjs
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Rsvpjs
2
+ module Rails
3
+ VERSION = "3.0.11"
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rsvpjs/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rsvpjs-rails"
8
+ spec.version = Rsvpjs::Rails::VERSION
9
+ spec.authors = ["Theodoros Orfanidis"]
10
+ spec.email = ["theo@incrediblue.com"]
11
+ spec.summary = %q{RSVP.js for the Rails asset pipeline.}
12
+ spec.homepage = "https://github.com/teoulas/rsvpjs-rails"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_dependency "railties", "~> 3.1"
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+ end
@@ -0,0 +1,1604 @@
1
+ /*!
2
+ * @overview RSVP - a tiny implementation of Promises/A+.
3
+ * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors
4
+ * @license Licensed under MIT license
5
+ * See https://raw.githubusercontent.com/tildeio/rsvp.js/master/LICENSE
6
+ * @version 3.0.11
7
+ */
8
+
9
+ (function() {
10
+ "use strict";
11
+
12
+ function $$rsvp$events$$indexOf(callbacks, callback) {
13
+ for (var i=0, l=callbacks.length; i<l; i++) {
14
+ if (callbacks[i] === callback) { return i; }
15
+ }
16
+
17
+ return -1;
18
+ }
19
+
20
+ function $$rsvp$events$$callbacksFor(object) {
21
+ var callbacks = object._promiseCallbacks;
22
+
23
+ if (!callbacks) {
24
+ callbacks = object._promiseCallbacks = {};
25
+ }
26
+
27
+ return callbacks;
28
+ }
29
+
30
+ var $$rsvp$events$$default = {
31
+
32
+ /**
33
+ `RSVP.EventTarget.mixin` extends an object with EventTarget methods. For
34
+ Example:
35
+
36
+ ```javascript
37
+ var object = {};
38
+
39
+ RSVP.EventTarget.mixin(object);
40
+
41
+ object.on('finished', function(event) {
42
+ // handle event
43
+ });
44
+
45
+ object.trigger('finished', { detail: value });
46
+ ```
47
+
48
+ `EventTarget.mixin` also works with prototypes:
49
+
50
+ ```javascript
51
+ var Person = function() {};
52
+ RSVP.EventTarget.mixin(Person.prototype);
53
+
54
+ var yehuda = new Person();
55
+ var tom = new Person();
56
+
57
+ yehuda.on('poke', function(event) {
58
+ console.log('Yehuda says OW');
59
+ });
60
+
61
+ tom.on('poke', function(event) {
62
+ console.log('Tom says OW');
63
+ });
64
+
65
+ yehuda.trigger('poke');
66
+ tom.trigger('poke');
67
+ ```
68
+
69
+ @method mixin
70
+ @for RSVP.EventTarget
71
+ @private
72
+ @param {Object} object object to extend with EventTarget methods
73
+ */
74
+ mixin: function(object) {
75
+ object.on = this.on;
76
+ object.off = this.off;
77
+ object.trigger = this.trigger;
78
+ object._promiseCallbacks = undefined;
79
+ return object;
80
+ },
81
+
82
+ /**
83
+ Registers a callback to be executed when `eventName` is triggered
84
+
85
+ ```javascript
86
+ object.on('event', function(eventInfo){
87
+ // handle the event
88
+ });
89
+
90
+ object.trigger('event');
91
+ ```
92
+
93
+ @method on
94
+ @for RSVP.EventTarget
95
+ @private
96
+ @param {String} eventName name of the event to listen for
97
+ @param {Function} callback function to be called when the event is triggered.
98
+ */
99
+ on: function(eventName, callback) {
100
+ var allCallbacks = $$rsvp$events$$callbacksFor(this), callbacks;
101
+
102
+ callbacks = allCallbacks[eventName];
103
+
104
+ if (!callbacks) {
105
+ callbacks = allCallbacks[eventName] = [];
106
+ }
107
+
108
+ if ($$rsvp$events$$indexOf(callbacks, callback) === -1) {
109
+ callbacks.push(callback);
110
+ }
111
+ },
112
+
113
+ /**
114
+ You can use `off` to stop firing a particular callback for an event:
115
+
116
+ ```javascript
117
+ function doStuff() { // do stuff! }
118
+ object.on('stuff', doStuff);
119
+
120
+ object.trigger('stuff'); // doStuff will be called
121
+
122
+ // Unregister ONLY the doStuff callback
123
+ object.off('stuff', doStuff);
124
+ object.trigger('stuff'); // doStuff will NOT be called
125
+ ```
126
+
127
+ If you don't pass a `callback` argument to `off`, ALL callbacks for the
128
+ event will not be executed when the event fires. For example:
129
+
130
+ ```javascript
131
+ var callback1 = function(){};
132
+ var callback2 = function(){};
133
+
134
+ object.on('stuff', callback1);
135
+ object.on('stuff', callback2);
136
+
137
+ object.trigger('stuff'); // callback1 and callback2 will be executed.
138
+
139
+ object.off('stuff');
140
+ object.trigger('stuff'); // callback1 and callback2 will not be executed!
141
+ ```
142
+
143
+ @method off
144
+ @for RSVP.EventTarget
145
+ @private
146
+ @param {String} eventName event to stop listening to
147
+ @param {Function} callback optional argument. If given, only the function
148
+ given will be removed from the event's callback queue. If no `callback`
149
+ argument is given, all callbacks will be removed from the event's callback
150
+ queue.
151
+ */
152
+ off: function(eventName, callback) {
153
+ var allCallbacks = $$rsvp$events$$callbacksFor(this), callbacks, index;
154
+
155
+ if (!callback) {
156
+ allCallbacks[eventName] = [];
157
+ return;
158
+ }
159
+
160
+ callbacks = allCallbacks[eventName];
161
+
162
+ index = $$rsvp$events$$indexOf(callbacks, callback);
163
+
164
+ if (index !== -1) { callbacks.splice(index, 1); }
165
+ },
166
+
167
+ /**
168
+ Use `trigger` to fire custom events. For example:
169
+
170
+ ```javascript
171
+ object.on('foo', function(){
172
+ console.log('foo event happened!');
173
+ });
174
+ object.trigger('foo');
175
+ // 'foo event happened!' logged to the console
176
+ ```
177
+
178
+ You can also pass a value as a second argument to `trigger` that will be
179
+ passed as an argument to all event listeners for the event:
180
+
181
+ ```javascript
182
+ object.on('foo', function(value){
183
+ console.log(value.name);
184
+ });
185
+
186
+ object.trigger('foo', { name: 'bar' });
187
+ // 'bar' logged to the console
188
+ ```
189
+
190
+ @method trigger
191
+ @for RSVP.EventTarget
192
+ @private
193
+ @param {String} eventName name of the event to be triggered
194
+ @param {Any} options optional value to be passed to any event handlers for
195
+ the given `eventName`
196
+ */
197
+ trigger: function(eventName, options) {
198
+ var allCallbacks = $$rsvp$events$$callbacksFor(this), callbacks, callback;
199
+
200
+ if (callbacks = allCallbacks[eventName]) {
201
+ // Don't cache the callbacks.length since it may grow
202
+ for (var i=0; i<callbacks.length; i++) {
203
+ callback = callbacks[i];
204
+
205
+ callback(options);
206
+ }
207
+ }
208
+ }
209
+ };
210
+
211
+ var $$rsvp$config$$config = {
212
+ instrument: false
213
+ };
214
+
215
+ $$rsvp$events$$default.mixin($$rsvp$config$$config);
216
+
217
+ function $$rsvp$config$$configure(name, value) {
218
+ if (name === 'onerror') {
219
+ // handle for legacy users that expect the actual
220
+ // error to be passed to their function added via
221
+ // `RSVP.configure('onerror', someFunctionHere);`
222
+ $$rsvp$config$$config.on('error', value);
223
+ return;
224
+ }
225
+
226
+ if (arguments.length === 2) {
227
+ $$rsvp$config$$config[name] = value;
228
+ } else {
229
+ return $$rsvp$config$$config[name];
230
+ }
231
+ }
232
+
233
+ function $$utils$$objectOrFunction(x) {
234
+ return typeof x === 'function' || (typeof x === 'object' && x !== null);
235
+ }
236
+
237
+ function $$utils$$isFunction(x) {
238
+ return typeof x === 'function';
239
+ }
240
+
241
+ function $$utils$$isMaybeThenable(x) {
242
+ return typeof x === 'object' && x !== null;
243
+ }
244
+
245
+ var $$utils$$_isArray;
246
+
247
+ if (!Array.isArray) {
248
+ $$utils$$_isArray = function (x) {
249
+ return Object.prototype.toString.call(x) === '[object Array]';
250
+ };
251
+ } else {
252
+ $$utils$$_isArray = Array.isArray;
253
+ }
254
+
255
+ var $$utils$$isArray = $$utils$$_isArray;
256
+ var $$utils$$now = Date.now || function() { return new Date().getTime(); };
257
+
258
+ var $$utils$$o_create = (Object.create || function(object) {
259
+ var o = function() { };
260
+ o.prototype = object;
261
+ return o;
262
+ });
263
+
264
+ var $$instrument$$queue = [];
265
+
266
+ var $$instrument$$default = function instrument(eventName, promise, child) {
267
+ if (1 === $$instrument$$queue.push({
268
+ name: eventName,
269
+ payload: {
270
+ guid: promise._guidKey + promise._id,
271
+ eventName: eventName,
272
+ detail: promise._result,
273
+ childGuid: child && promise._guidKey + child._id,
274
+ label: promise._label,
275
+ timeStamp: $$utils$$now(),
276
+ stack: new Error(promise._label).stack
277
+ }})) {
278
+
279
+ setTimeout(function() {
280
+ var entry;
281
+ for (var i = 0; i < $$instrument$$queue.length; i++) {
282
+ entry = $$instrument$$queue[i];
283
+ $$rsvp$config$$config.trigger(entry.name, entry.payload);
284
+ }
285
+ $$instrument$$queue.length = 0;
286
+ }, 50);
287
+ }
288
+ };
289
+
290
+ function $$$internal$$noop() {}
291
+ var $$$internal$$PENDING = void 0;
292
+ var $$$internal$$FULFILLED = 1;
293
+ var $$$internal$$REJECTED = 2;
294
+ var $$$internal$$GET_THEN_ERROR = new $$$internal$$ErrorObject();
295
+
296
+ function $$$internal$$getThen(promise) {
297
+ try {
298
+ return promise.then;
299
+ } catch(error) {
300
+ $$$internal$$GET_THEN_ERROR.error = error;
301
+ return $$$internal$$GET_THEN_ERROR;
302
+ }
303
+ }
304
+
305
+ function $$$internal$$tryThen(then, value, fulfillmentHandler, rejectionHandler) {
306
+ try {
307
+ then.call(value, fulfillmentHandler, rejectionHandler);
308
+ } catch(e) {
309
+ return e;
310
+ }
311
+ }
312
+
313
+ function $$$internal$$handleForeignThenable(promise, thenable, then) {
314
+ $$rsvp$config$$config.async(function(promise) {
315
+ var sealed = false;
316
+ var error = $$$internal$$tryThen(then, thenable, function(value) {
317
+ if (sealed) { return; }
318
+ sealed = true;
319
+ if (thenable !== value) {
320
+ $$$internal$$resolve(promise, value);
321
+ } else {
322
+ $$$internal$$fulfill(promise, value);
323
+ }
324
+ }, function(reason) {
325
+ if (sealed) { return; }
326
+ sealed = true;
327
+
328
+ $$$internal$$reject(promise, reason);
329
+ }, 'Settle: ' + (promise._label || ' unknown promise'));
330
+
331
+ if (!sealed && error) {
332
+ sealed = true;
333
+ $$$internal$$reject(promise, error);
334
+ }
335
+ }, promise);
336
+ }
337
+
338
+ function $$$internal$$handleOwnThenable(promise, thenable) {
339
+ if (thenable._state === $$$internal$$FULFILLED) {
340
+ $$$internal$$fulfill(promise, thenable._result);
341
+ } else if (promise._state === $$$internal$$REJECTED) {
342
+ $$$internal$$reject(promise, thenable._result);
343
+ } else {
344
+ $$$internal$$subscribe(thenable, undefined, function(value) {
345
+ if (thenable !== value) {
346
+ $$$internal$$resolve(promise, value);
347
+ } else {
348
+ $$$internal$$fulfill(promise, value);
349
+ }
350
+ }, function(reason) {
351
+ $$$internal$$reject(promise, reason);
352
+ });
353
+ }
354
+ }
355
+
356
+ function $$$internal$$handleMaybeThenable(promise, maybeThenable) {
357
+ if (maybeThenable.constructor === promise.constructor) {
358
+ $$$internal$$handleOwnThenable(promise, maybeThenable);
359
+ } else {
360
+ var then = $$$internal$$getThen(maybeThenable);
361
+
362
+ if (then === $$$internal$$GET_THEN_ERROR) {
363
+ $$$internal$$reject(promise, $$$internal$$GET_THEN_ERROR.error);
364
+ } else if (then === undefined) {
365
+ $$$internal$$fulfill(promise, maybeThenable);
366
+ } else if ($$utils$$isFunction(then)) {
367
+ $$$internal$$handleForeignThenable(promise, maybeThenable, then);
368
+ } else {
369
+ $$$internal$$fulfill(promise, maybeThenable);
370
+ }
371
+ }
372
+ }
373
+
374
+ function $$$internal$$resolve(promise, value) {
375
+ if (promise === value) {
376
+ $$$internal$$fulfill(promise, value);
377
+ } else if ($$utils$$objectOrFunction(value)) {
378
+ $$$internal$$handleMaybeThenable(promise, value);
379
+ } else {
380
+ $$$internal$$fulfill(promise, value);
381
+ }
382
+ }
383
+
384
+ function $$$internal$$publishRejection(promise) {
385
+ if (promise._onerror) {
386
+ promise._onerror(promise._result);
387
+ }
388
+
389
+ $$$internal$$publish(promise);
390
+ }
391
+
392
+ function $$$internal$$fulfill(promise, value) {
393
+ if (promise._state !== $$$internal$$PENDING) { return; }
394
+
395
+ promise._result = value;
396
+ promise._state = $$$internal$$FULFILLED;
397
+
398
+ if (promise._subscribers.length === 0) {
399
+ if ($$rsvp$config$$config.instrument) {
400
+ $$instrument$$default('fulfilled', promise);
401
+ }
402
+ } else {
403
+ $$rsvp$config$$config.async($$$internal$$publish, promise);
404
+ }
405
+ }
406
+
407
+ function $$$internal$$reject(promise, reason) {
408
+ if (promise._state !== $$$internal$$PENDING) { return; }
409
+ promise._state = $$$internal$$REJECTED;
410
+ promise._result = reason;
411
+
412
+ $$rsvp$config$$config.async($$$internal$$publishRejection, promise);
413
+ }
414
+
415
+ function $$$internal$$subscribe(parent, child, onFulfillment, onRejection) {
416
+ var subscribers = parent._subscribers;
417
+ var length = subscribers.length;
418
+
419
+ parent._onerror = null;
420
+
421
+ subscribers[length] = child;
422
+ subscribers[length + $$$internal$$FULFILLED] = onFulfillment;
423
+ subscribers[length + $$$internal$$REJECTED] = onRejection;
424
+
425
+ if (length === 0 && parent._state) {
426
+ $$rsvp$config$$config.async($$$internal$$publish, parent);
427
+ }
428
+ }
429
+
430
+ function $$$internal$$publish(promise) {
431
+ var subscribers = promise._subscribers;
432
+ var settled = promise._state;
433
+
434
+ if ($$rsvp$config$$config.instrument) {
435
+ $$instrument$$default(settled === $$$internal$$FULFILLED ? 'fulfilled' : 'rejected', promise);
436
+ }
437
+
438
+ if (subscribers.length === 0) { return; }
439
+
440
+ var child, callback, detail = promise._result;
441
+
442
+ for (var i = 0; i < subscribers.length; i += 3) {
443
+ child = subscribers[i];
444
+ callback = subscribers[i + settled];
445
+
446
+ if (child) {
447
+ $$$internal$$invokeCallback(settled, child, callback, detail);
448
+ } else {
449
+ callback(detail);
450
+ }
451
+ }
452
+
453
+ promise._subscribers.length = 0;
454
+ }
455
+
456
+ function $$$internal$$ErrorObject() {
457
+ this.error = null;
458
+ }
459
+
460
+ var $$$internal$$TRY_CATCH_ERROR = new $$$internal$$ErrorObject();
461
+
462
+ function $$$internal$$tryCatch(callback, detail) {
463
+ try {
464
+ return callback(detail);
465
+ } catch(e) {
466
+ $$$internal$$TRY_CATCH_ERROR.error = e;
467
+ return $$$internal$$TRY_CATCH_ERROR;
468
+ }
469
+ }
470
+
471
+ function $$$internal$$invokeCallback(settled, promise, callback, detail) {
472
+ var hasCallback = $$utils$$isFunction(callback),
473
+ value, error, succeeded, failed;
474
+
475
+ if (hasCallback) {
476
+ value = $$$internal$$tryCatch(callback, detail);
477
+
478
+ if (value === $$$internal$$TRY_CATCH_ERROR) {
479
+ failed = true;
480
+ error = value.error;
481
+ value = null;
482
+ } else {
483
+ succeeded = true;
484
+ }
485
+
486
+ if (promise === value) {
487
+ $$$internal$$reject(promise, new TypeError('A promises callback cannot return that same promise.'));
488
+ return;
489
+ }
490
+
491
+ } else {
492
+ value = detail;
493
+ succeeded = true;
494
+ }
495
+
496
+ if (promise._state !== $$$internal$$PENDING) {
497
+ // noop
498
+ } else if (hasCallback && succeeded) {
499
+ $$$internal$$resolve(promise, value);
500
+ } else if (failed) {
501
+ $$$internal$$reject(promise, error);
502
+ } else if (settled === $$$internal$$FULFILLED) {
503
+ $$$internal$$fulfill(promise, value);
504
+ } else if (settled === $$$internal$$REJECTED) {
505
+ $$$internal$$reject(promise, value);
506
+ }
507
+ }
508
+
509
+ function $$$internal$$initializePromise(promise, resolver) {
510
+ try {
511
+ resolver(function resolvePromise(value){
512
+ $$$internal$$resolve(promise, value);
513
+ }, function rejectPromise(reason) {
514
+ $$$internal$$reject(promise, reason);
515
+ });
516
+ } catch(e) {
517
+ $$$internal$$reject(promise, e);
518
+ }
519
+ }
520
+
521
+ function $$enumerator$$makeSettledResult(state, position, value) {
522
+ if (state === $$$internal$$FULFILLED) {
523
+ return {
524
+ state: 'fulfilled',
525
+ value: value
526
+ };
527
+ } else {
528
+ return {
529
+ state: 'rejected',
530
+ reason: value
531
+ };
532
+ }
533
+ }
534
+
535
+ function $$enumerator$$Enumerator(Constructor, input, abortOnReject, label) {
536
+ this._instanceConstructor = Constructor;
537
+ this.promise = new Constructor($$$internal$$noop, label);
538
+ this._abortOnReject = abortOnReject;
539
+
540
+ if (this._validateInput(input)) {
541
+ this._input = input;
542
+ this.length = input.length;
543
+ this._remaining = input.length;
544
+
545
+ this._init();
546
+
547
+ if (this.length === 0) {
548
+ $$$internal$$fulfill(this.promise, this._result);
549
+ } else {
550
+ this.length = this.length || 0;
551
+ this._enumerate();
552
+ if (this._remaining === 0) {
553
+ $$$internal$$fulfill(this.promise, this._result);
554
+ }
555
+ }
556
+ } else {
557
+ $$$internal$$reject(this.promise, this._validationError());
558
+ }
559
+ }
560
+
561
+ $$enumerator$$Enumerator.prototype._validateInput = function(input) {
562
+ return $$utils$$isArray(input);
563
+ };
564
+
565
+ $$enumerator$$Enumerator.prototype._validationError = function() {
566
+ return new Error('Array Methods must be provided an Array');
567
+ };
568
+
569
+ $$enumerator$$Enumerator.prototype._init = function() {
570
+ this._result = new Array(this.length);
571
+ };
572
+
573
+ var $$enumerator$$default = $$enumerator$$Enumerator;
574
+
575
+ $$enumerator$$Enumerator.prototype._enumerate = function() {
576
+ var length = this.length;
577
+ var promise = this.promise;
578
+ var input = this._input;
579
+
580
+ for (var i = 0; promise._state === $$$internal$$PENDING && i < length; i++) {
581
+ this._eachEntry(input[i], i);
582
+ }
583
+ };
584
+
585
+ $$enumerator$$Enumerator.prototype._eachEntry = function(entry, i) {
586
+ var c = this._instanceConstructor;
587
+ if ($$utils$$isMaybeThenable(entry)) {
588
+ if (entry.constructor === c && entry._state !== $$$internal$$PENDING) {
589
+ entry._onerror = null;
590
+ this._settledAt(entry._state, i, entry._result);
591
+ } else {
592
+ this._willSettleAt(c.resolve(entry), i);
593
+ }
594
+ } else {
595
+ this._remaining--;
596
+ this._result[i] = this._makeResult($$$internal$$FULFILLED, i, entry);
597
+ }
598
+ };
599
+
600
+ $$enumerator$$Enumerator.prototype._settledAt = function(state, i, value) {
601
+ var promise = this.promise;
602
+
603
+ if (promise._state === $$$internal$$PENDING) {
604
+ this._remaining--;
605
+
606
+ if (this._abortOnReject && state === $$$internal$$REJECTED) {
607
+ $$$internal$$reject(promise, value);
608
+ } else {
609
+ this._result[i] = this._makeResult(state, i, value);
610
+ }
611
+ }
612
+
613
+ if (this._remaining === 0) {
614
+ $$$internal$$fulfill(promise, this._result);
615
+ }
616
+ };
617
+
618
+ $$enumerator$$Enumerator.prototype._makeResult = function(state, i, value) {
619
+ return value;
620
+ };
621
+
622
+ $$enumerator$$Enumerator.prototype._willSettleAt = function(promise, i) {
623
+ var enumerator = this;
624
+
625
+ $$$internal$$subscribe(promise, undefined, function(value) {
626
+ enumerator._settledAt($$$internal$$FULFILLED, i, value);
627
+ }, function(reason) {
628
+ enumerator._settledAt($$$internal$$REJECTED, i, reason);
629
+ });
630
+ };
631
+
632
+ var $$promise$all$$default = function all(entries, label) {
633
+ return new $$enumerator$$default(this, entries, true /* abort on reject */, label).promise;
634
+ };
635
+
636
+ var $$promise$race$$default = function race(entries, label) {
637
+ /*jshint validthis:true */
638
+ var Constructor = this;
639
+
640
+ var promise = new Constructor($$$internal$$noop, label);
641
+
642
+ if (!$$utils$$isArray(entries)) {
643
+ $$$internal$$reject(promise, new TypeError('You must pass an array to race.'));
644
+ return promise;
645
+ }
646
+
647
+ var length = entries.length;
648
+
649
+ function onFulfillment(value) {
650
+ $$$internal$$resolve(promise, value);
651
+ }
652
+
653
+ function onRejection(reason) {
654
+ $$$internal$$reject(promise, reason);
655
+ }
656
+
657
+ for (var i = 0; promise._state === $$$internal$$PENDING && i < length; i++) {
658
+ $$$internal$$subscribe(Constructor.resolve(entries[i]), undefined, onFulfillment, onRejection);
659
+ }
660
+
661
+ return promise;
662
+ };
663
+
664
+ var $$promise$resolve$$default = function resolve(object, label) {
665
+ /*jshint validthis:true */
666
+ var Constructor = this;
667
+
668
+ if (object && typeof object === 'object' && object.constructor === Constructor) {
669
+ return object;
670
+ }
671
+
672
+ var promise = new Constructor($$$internal$$noop, label);
673
+ $$$internal$$resolve(promise, object);
674
+ return promise;
675
+ };
676
+
677
+ var $$promise$reject$$default = function reject(reason, label) {
678
+ /*jshint validthis:true */
679
+ var Constructor = this;
680
+ var promise = new Constructor($$$internal$$noop, label);
681
+ $$$internal$$reject(promise, reason);
682
+ return promise;
683
+ };
684
+
685
+ var $$rsvp$promise$$guidKey = 'rsvp_' + $$utils$$now() + '-';
686
+ var $$rsvp$promise$$counter = 0;
687
+
688
+ function $$rsvp$promise$$needsResolver() {
689
+ throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
690
+ }
691
+
692
+ function $$rsvp$promise$$needsNew() {
693
+ throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
694
+ }
695
+
696
+ var $$rsvp$promise$$default = $$rsvp$promise$$Promise;
697
+
698
+ /**
699
+ Promise objects represent the eventual result of an asynchronous operation. The
700
+ primary way of interacting with a promise is through its `then` method, which
701
+ registers callbacks to receive either a promise’s eventual value or the reason
702
+ why the promise cannot be fulfilled.
703
+
704
+ Terminology
705
+ -----------
706
+
707
+ - `promise` is an object or function with a `then` method whose behavior conforms to this specification.
708
+ - `thenable` is an object or function that defines a `then` method.
709
+ - `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
710
+ - `exception` is a value that is thrown using the throw statement.
711
+ - `reason` is a value that indicates why a promise was rejected.
712
+ - `settled` the final resting state of a promise, fulfilled or rejected.
713
+
714
+ A promise can be in one of three states: pending, fulfilled, or rejected.
715
+
716
+ Promises that are fulfilled have a fulfillment value and are in the fulfilled
717
+ state. Promises that are rejected have a rejection reason and are in the
718
+ rejected state. A fulfillment value is never a thenable.
719
+
720
+ Promises can also be said to *resolve* a value. If this value is also a
721
+ promise, then the original promise's settled state will match the value's
722
+ settled state. So a promise that *resolves* a promise that rejects will
723
+ itself reject, and a promise that *resolves* a promise that fulfills will
724
+ itself fulfill.
725
+
726
+
727
+ Basic Usage:
728
+ ------------
729
+
730
+ ```js
731
+ var promise = new Promise(function(resolve, reject) {
732
+ // on success
733
+ resolve(value);
734
+
735
+ // on failure
736
+ reject(reason);
737
+ });
738
+
739
+ promise.then(function(value) {
740
+ // on fulfillment
741
+ }, function(reason) {
742
+ // on rejection
743
+ });
744
+ ```
745
+
746
+ Advanced Usage:
747
+ ---------------
748
+
749
+ Promises shine when abstracting away asynchronous interactions such as
750
+ `XMLHttpRequest`s.
751
+
752
+ ```js
753
+ function getJSON(url) {
754
+ return new Promise(function(resolve, reject){
755
+ var xhr = new XMLHttpRequest();
756
+
757
+ xhr.open('GET', url);
758
+ xhr.onreadystatechange = handler;
759
+ xhr.responseType = 'json';
760
+ xhr.setRequestHeader('Accept', 'application/json');
761
+ xhr.send();
762
+
763
+ function handler() {
764
+ if (this.readyState === this.DONE) {
765
+ if (this.status === 200) {
766
+ resolve(this.response);
767
+ } else {
768
+ reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
769
+ }
770
+ }
771
+ };
772
+ });
773
+ }
774
+
775
+ getJSON('/posts.json').then(function(json) {
776
+ // on fulfillment
777
+ }, function(reason) {
778
+ // on rejection
779
+ });
780
+ ```
781
+
782
+ Unlike callbacks, promises are great composable primitives.
783
+
784
+ ```js
785
+ Promise.all([
786
+ getJSON('/posts'),
787
+ getJSON('/comments')
788
+ ]).then(function(values){
789
+ values[0] // => postsJSON
790
+ values[1] // => commentsJSON
791
+
792
+ return values;
793
+ });
794
+ ```
795
+
796
+ @class RSVP.Promise
797
+ @param {function} resolver
798
+ @param {String} label optional string for labeling the promise.
799
+ Useful for tooling.
800
+ @constructor
801
+ */
802
+ function $$rsvp$promise$$Promise(resolver, label) {
803
+ this._id = $$rsvp$promise$$counter++;
804
+ this._label = label;
805
+ this._state = undefined;
806
+ this._result = undefined;
807
+ this._subscribers = [];
808
+
809
+ if ($$rsvp$config$$config.instrument) {
810
+ $$instrument$$default('created', this);
811
+ }
812
+
813
+ if ($$$internal$$noop !== resolver) {
814
+ if (!$$utils$$isFunction(resolver)) {
815
+ $$rsvp$promise$$needsResolver();
816
+ }
817
+
818
+ if (!(this instanceof $$rsvp$promise$$Promise)) {
819
+ $$rsvp$promise$$needsNew();
820
+ }
821
+
822
+ $$$internal$$initializePromise(this, resolver);
823
+ }
824
+ }
825
+
826
+ // deprecated
827
+ $$rsvp$promise$$Promise.cast = $$promise$resolve$$default;
828
+
829
+ $$rsvp$promise$$Promise.all = $$promise$all$$default;
830
+ $$rsvp$promise$$Promise.race = $$promise$race$$default;
831
+ $$rsvp$promise$$Promise.resolve = $$promise$resolve$$default;
832
+ $$rsvp$promise$$Promise.reject = $$promise$reject$$default;
833
+
834
+ $$rsvp$promise$$Promise.prototype = {
835
+ constructor: $$rsvp$promise$$Promise,
836
+
837
+ _guidKey: $$rsvp$promise$$guidKey,
838
+
839
+ _onerror: function (reason) {
840
+ $$rsvp$config$$config.trigger('error', reason);
841
+ },
842
+
843
+ /**
844
+ The primary way of interacting with a promise is through its `then` method,
845
+ which registers callbacks to receive either a promise's eventual value or the
846
+ reason why the promise cannot be fulfilled.
847
+
848
+ ```js
849
+ findUser().then(function(user){
850
+ // user is available
851
+ }, function(reason){
852
+ // user is unavailable, and you are given the reason why
853
+ });
854
+ ```
855
+
856
+ Chaining
857
+ --------
858
+
859
+ The return value of `then` is itself a promise. This second, 'downstream'
860
+ promise is resolved with the return value of the first promise's fulfillment
861
+ or rejection handler, or rejected if the handler throws an exception.
862
+
863
+ ```js
864
+ findUser().then(function (user) {
865
+ return user.name;
866
+ }, function (reason) {
867
+ return 'default name';
868
+ }).then(function (userName) {
869
+ // If `findUser` fulfilled, `userName` will be the user's name, otherwise it
870
+ // will be `'default name'`
871
+ });
872
+
873
+ findUser().then(function (user) {
874
+ throw new Error('Found user, but still unhappy');
875
+ }, function (reason) {
876
+ throw new Error('`findUser` rejected and we're unhappy');
877
+ }).then(function (value) {
878
+ // never reached
879
+ }, function (reason) {
880
+ // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
881
+ // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
882
+ });
883
+ ```
884
+ If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
885
+
886
+ ```js
887
+ findUser().then(function (user) {
888
+ throw new PedagogicalException('Upstream error');
889
+ }).then(function (value) {
890
+ // never reached
891
+ }).then(function (value) {
892
+ // never reached
893
+ }, function (reason) {
894
+ // The `PedgagocialException` is propagated all the way down to here
895
+ });
896
+ ```
897
+
898
+ Assimilation
899
+ ------------
900
+
901
+ Sometimes the value you want to propagate to a downstream promise can only be
902
+ retrieved asynchronously. This can be achieved by returning a promise in the
903
+ fulfillment or rejection handler. The downstream promise will then be pending
904
+ until the returned promise is settled. This is called *assimilation*.
905
+
906
+ ```js
907
+ findUser().then(function (user) {
908
+ return findCommentsByAuthor(user);
909
+ }).then(function (comments) {
910
+ // The user's comments are now available
911
+ });
912
+ ```
913
+
914
+ If the assimliated promise rejects, then the downstream promise will also reject.
915
+
916
+ ```js
917
+ findUser().then(function (user) {
918
+ return findCommentsByAuthor(user);
919
+ }).then(function (comments) {
920
+ // If `findCommentsByAuthor` fulfills, we'll have the value here
921
+ }, function (reason) {
922
+ // If `findCommentsByAuthor` rejects, we'll have the reason here
923
+ });
924
+ ```
925
+
926
+ Simple Example
927
+ --------------
928
+
929
+ Synchronous Example
930
+
931
+ ```javascript
932
+ var result;
933
+
934
+ try {
935
+ result = findResult();
936
+ // success
937
+ } catch(reason) {
938
+ // failure
939
+ }
940
+ ```
941
+
942
+ Errback Example
943
+
944
+ ```js
945
+ findResult(function(result, err){
946
+ if (err) {
947
+ // failure
948
+ } else {
949
+ // success
950
+ }
951
+ });
952
+ ```
953
+
954
+ Promise Example;
955
+
956
+ ```javascript
957
+ findResult().then(function(result){
958
+ // success
959
+ }, function(reason){
960
+ // failure
961
+ });
962
+ ```
963
+
964
+ Advanced Example
965
+ --------------
966
+
967
+ Synchronous Example
968
+
969
+ ```javascript
970
+ var author, books;
971
+
972
+ try {
973
+ author = findAuthor();
974
+ books = findBooksByAuthor(author);
975
+ // success
976
+ } catch(reason) {
977
+ // failure
978
+ }
979
+ ```
980
+
981
+ Errback Example
982
+
983
+ ```js
984
+
985
+ function foundBooks(books) {
986
+
987
+ }
988
+
989
+ function failure(reason) {
990
+
991
+ }
992
+
993
+ findAuthor(function(author, err){
994
+ if (err) {
995
+ failure(err);
996
+ // failure
997
+ } else {
998
+ try {
999
+ findBoooksByAuthor(author, function(books, err) {
1000
+ if (err) {
1001
+ failure(err);
1002
+ } else {
1003
+ try {
1004
+ foundBooks(books);
1005
+ } catch(reason) {
1006
+ failure(reason);
1007
+ }
1008
+ }
1009
+ });
1010
+ } catch(error) {
1011
+ failure(err);
1012
+ }
1013
+ // success
1014
+ }
1015
+ });
1016
+ ```
1017
+
1018
+ Promise Example;
1019
+
1020
+ ```javascript
1021
+ findAuthor().
1022
+ then(findBooksByAuthor).
1023
+ then(function(books){
1024
+ // found books
1025
+ }).catch(function(reason){
1026
+ // something went wrong
1027
+ });
1028
+ ```
1029
+
1030
+ @method then
1031
+ @param {Function} onFulfilled
1032
+ @param {Function} onRejected
1033
+ @param {String} label optional string for labeling the promise.
1034
+ Useful for tooling.
1035
+ @return {Promise}
1036
+ */
1037
+ then: function(onFulfillment, onRejection, label) {
1038
+ var parent = this;
1039
+ var state = parent._state;
1040
+
1041
+ if (state === $$$internal$$FULFILLED && !onFulfillment || state === $$$internal$$REJECTED && !onRejection) {
1042
+ if ($$rsvp$config$$config.instrument) {
1043
+ $$instrument$$default('chained', this, this);
1044
+ }
1045
+ return this;
1046
+ }
1047
+
1048
+ parent._onerror = null;
1049
+
1050
+ var child = new this.constructor($$$internal$$noop, label);
1051
+ var result = parent._result;
1052
+
1053
+ if ($$rsvp$config$$config.instrument) {
1054
+ $$instrument$$default('chained', parent, child);
1055
+ }
1056
+
1057
+ if (state) {
1058
+ var callback = arguments[state - 1];
1059
+ $$rsvp$config$$config.async(function(){
1060
+ $$$internal$$invokeCallback(state, child, callback, result);
1061
+ });
1062
+ } else {
1063
+ $$$internal$$subscribe(parent, child, onFulfillment, onRejection);
1064
+ }
1065
+
1066
+ return child;
1067
+ },
1068
+
1069
+ /**
1070
+ `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
1071
+ as the catch block of a try/catch statement.
1072
+
1073
+ ```js
1074
+ function findAuthor(){
1075
+ throw new Error('couldn't find that author');
1076
+ }
1077
+
1078
+ // synchronous
1079
+ try {
1080
+ findAuthor();
1081
+ } catch(reason) {
1082
+ // something went wrong
1083
+ }
1084
+
1085
+ // async with promises
1086
+ findAuthor().catch(function(reason){
1087
+ // something went wrong
1088
+ });
1089
+ ```
1090
+
1091
+ @method catch
1092
+ @param {Function} onRejection
1093
+ @param {String} label optional string for labeling the promise.
1094
+ Useful for tooling.
1095
+ @return {Promise}
1096
+ */
1097
+ 'catch': function(onRejection, label) {
1098
+ return this.then(null, onRejection, label);
1099
+ },
1100
+
1101
+ /**
1102
+ `finally` will be invoked regardless of the promise's fate just as native
1103
+ try/catch/finally behaves
1104
+
1105
+ Synchronous example:
1106
+
1107
+ ```js
1108
+ findAuthor() {
1109
+ if (Math.random() > 0.5) {
1110
+ throw new Error();
1111
+ }
1112
+ return new Author();
1113
+ }
1114
+
1115
+ try {
1116
+ return findAuthor(); // succeed or fail
1117
+ } catch(error) {
1118
+ return findOtherAuther();
1119
+ } finally {
1120
+ // always runs
1121
+ // doesn't affect the return value
1122
+ }
1123
+ ```
1124
+
1125
+ Asynchronous example:
1126
+
1127
+ ```js
1128
+ findAuthor().catch(function(reason){
1129
+ return findOtherAuther();
1130
+ }).finally(function(){
1131
+ // author was either found, or not
1132
+ });
1133
+ ```
1134
+
1135
+ @method finally
1136
+ @param {Function} callback
1137
+ @param {String} label optional string for labeling the promise.
1138
+ Useful for tooling.
1139
+ @return {Promise}
1140
+ */
1141
+ 'finally': function(callback, label) {
1142
+ var constructor = this.constructor;
1143
+
1144
+ return this.then(function(value) {
1145
+ return constructor.resolve(callback()).then(function(){
1146
+ return value;
1147
+ });
1148
+ }, function(reason) {
1149
+ return constructor.resolve(callback()).then(function(){
1150
+ throw reason;
1151
+ });
1152
+ }, label);
1153
+ }
1154
+ };
1155
+
1156
+ function $$rsvp$node$$Result() {
1157
+ this.value = undefined;
1158
+ }
1159
+
1160
+ var $$rsvp$node$$ERROR = new $$rsvp$node$$Result();
1161
+ var $$rsvp$node$$GET_THEN_ERROR = new $$rsvp$node$$Result();
1162
+
1163
+ function $$rsvp$node$$getThen(obj) {
1164
+ try {
1165
+ return obj.then;
1166
+ } catch(error) {
1167
+ $$rsvp$node$$ERROR.value= error;
1168
+ return $$rsvp$node$$ERROR;
1169
+ }
1170
+ }
1171
+
1172
+ function $$rsvp$node$$tryApply(f, s, a) {
1173
+ try {
1174
+ f.apply(s, a);
1175
+ } catch(error) {
1176
+ $$rsvp$node$$ERROR.value = error;
1177
+ return $$rsvp$node$$ERROR;
1178
+ }
1179
+ }
1180
+
1181
+ function $$rsvp$node$$makeObject(_, argumentNames) {
1182
+ var obj = {};
1183
+ var name;
1184
+ var i;
1185
+ var length = _.length;
1186
+ var args = new Array(length);
1187
+
1188
+ for (var x = 0; x < length; x++) {
1189
+ args[x] = _[x];
1190
+ }
1191
+
1192
+ for (i = 0; i < argumentNames.length; i++) {
1193
+ name = argumentNames[i];
1194
+ obj[name] = args[i + 1];
1195
+ }
1196
+
1197
+ return obj;
1198
+ }
1199
+
1200
+ function $$rsvp$node$$arrayResult(_) {
1201
+ var length = _.length;
1202
+ var args = new Array(length - 1);
1203
+
1204
+ for (var i = 1; i < length; i++) {
1205
+ args[i - 1] = _[i];
1206
+ }
1207
+
1208
+ return args;
1209
+ }
1210
+
1211
+ function $$rsvp$node$$wrapThenable(then, promise) {
1212
+ return {
1213
+ then: function(onFulFillment, onRejection) {
1214
+ return then.call(promise, onFulFillment, onRejection);
1215
+ }
1216
+ };
1217
+ }
1218
+
1219
+ var $$rsvp$node$$default = function denodeify(nodeFunc, options) {
1220
+ var fn = function() {
1221
+ var self = this;
1222
+ var l = arguments.length;
1223
+ var args = new Array(l + 1);
1224
+ var arg;
1225
+ var promiseInput = false;
1226
+
1227
+ for (var i = 0; i < l; ++i) {
1228
+ arg = arguments[i];
1229
+
1230
+ if (!promiseInput) {
1231
+ // TODO: clean this up
1232
+ promiseInput = $$rsvp$node$$needsPromiseInput(arg);
1233
+ if (promiseInput === $$rsvp$node$$GET_THEN_ERROR) {
1234
+ var p = new $$rsvp$promise$$default($$$internal$$noop);
1235
+ $$$internal$$reject(p, $$rsvp$node$$GET_THEN_ERROR.value);
1236
+ return p;
1237
+ } else if (promiseInput && promiseInput !== true) {
1238
+ arg = $$rsvp$node$$wrapThenable(promiseInput, arg);
1239
+ }
1240
+ }
1241
+ args[i] = arg;
1242
+ }
1243
+
1244
+ var promise = new $$rsvp$promise$$default($$$internal$$noop);
1245
+
1246
+ args[l] = function(err, val) {
1247
+ if (err)
1248
+ $$$internal$$reject(promise, err);
1249
+ else if (options === undefined)
1250
+ $$$internal$$resolve(promise, val);
1251
+ else if (options === true)
1252
+ $$$internal$$resolve(promise, $$rsvp$node$$arrayResult(arguments));
1253
+ else if ($$utils$$isArray(options))
1254
+ $$$internal$$resolve(promise, $$rsvp$node$$makeObject(arguments, options));
1255
+ else
1256
+ $$$internal$$resolve(promise, val);
1257
+ };
1258
+
1259
+ if (promiseInput) {
1260
+ return $$rsvp$node$$handlePromiseInput(promise, args, nodeFunc, self);
1261
+ } else {
1262
+ return $$rsvp$node$$handleValueInput(promise, args, nodeFunc, self);
1263
+ }
1264
+ };
1265
+
1266
+ fn.__proto__ = nodeFunc;
1267
+
1268
+ return fn;
1269
+ };
1270
+
1271
+ function $$rsvp$node$$handleValueInput(promise, args, nodeFunc, self) {
1272
+ var result = $$rsvp$node$$tryApply(nodeFunc, self, args);
1273
+ if (result === $$rsvp$node$$ERROR) {
1274
+ $$$internal$$reject(promise, result.value);
1275
+ }
1276
+ return promise;
1277
+ }
1278
+
1279
+ function $$rsvp$node$$handlePromiseInput(promise, args, nodeFunc, self){
1280
+ return $$rsvp$promise$$default.all(args).then(function(args){
1281
+ var result = $$rsvp$node$$tryApply(nodeFunc, self, args);
1282
+ if (result === $$rsvp$node$$ERROR) {
1283
+ $$$internal$$reject(promise, result.value);
1284
+ }
1285
+ return promise;
1286
+ });
1287
+ }
1288
+
1289
+ function $$rsvp$node$$needsPromiseInput(arg) {
1290
+ if (arg && typeof arg === 'object') {
1291
+ if (arg.constructor === $$rsvp$promise$$default) {
1292
+ return true;
1293
+ } else {
1294
+ return $$rsvp$node$$getThen(arg);
1295
+ }
1296
+ } else {
1297
+ return false;
1298
+ }
1299
+ }
1300
+
1301
+ var $$rsvp$all$$default = function all(array, label) {
1302
+ return $$rsvp$promise$$default.all(array, label);
1303
+ };
1304
+
1305
+ function $$rsvp$all$settled$$AllSettled(Constructor, entries, label) {
1306
+ this._superConstructor(Constructor, entries, false /* don't abort on reject */, label);
1307
+ }
1308
+
1309
+ $$rsvp$all$settled$$AllSettled.prototype = $$utils$$o_create($$enumerator$$default.prototype);
1310
+ $$rsvp$all$settled$$AllSettled.prototype._superConstructor = $$enumerator$$default;
1311
+ $$rsvp$all$settled$$AllSettled.prototype._makeResult = $$enumerator$$makeSettledResult;
1312
+
1313
+ $$rsvp$all$settled$$AllSettled.prototype._validationError = function() {
1314
+ return new Error('allSettled must be called with an array');
1315
+ };
1316
+
1317
+ var $$rsvp$all$settled$$default = function allSettled(entries, label) {
1318
+ return new $$rsvp$all$settled$$AllSettled($$rsvp$promise$$default, entries, label).promise;
1319
+ };
1320
+
1321
+ var $$rsvp$race$$default = function race(array, label) {
1322
+ return $$rsvp$promise$$default.race(array, label);
1323
+ };
1324
+
1325
+ function $$promise$hash$$PromiseHash(Constructor, object, label) {
1326
+ this._superConstructor(Constructor, object, true, label);
1327
+ }
1328
+
1329
+ var $$promise$hash$$default = $$promise$hash$$PromiseHash;
1330
+ $$promise$hash$$PromiseHash.prototype = $$utils$$o_create($$enumerator$$default.prototype);
1331
+ $$promise$hash$$PromiseHash.prototype._superConstructor = $$enumerator$$default;
1332
+
1333
+ $$promise$hash$$PromiseHash.prototype._init = function() {
1334
+ this._result = {};
1335
+ };
1336
+
1337
+ $$promise$hash$$PromiseHash.prototype._validateInput = function(input) {
1338
+ return input && typeof input === 'object';
1339
+ };
1340
+
1341
+ $$promise$hash$$PromiseHash.prototype._validationError = function() {
1342
+ return new Error('Promise.hash must be called with an object');
1343
+ };
1344
+
1345
+ $$promise$hash$$PromiseHash.prototype._enumerate = function() {
1346
+ var promise = this.promise;
1347
+ var input = this._input;
1348
+ var results = [];
1349
+
1350
+ for (var key in input) {
1351
+ if (promise._state === $$$internal$$PENDING && input.hasOwnProperty(key)) {
1352
+ results.push({
1353
+ position: key,
1354
+ entry: input[key]
1355
+ });
1356
+ }
1357
+ }
1358
+
1359
+ var length = results.length;
1360
+ this._remaining = length;
1361
+ var result;
1362
+
1363
+ for (var i = 0; promise._state === $$$internal$$PENDING && i < length; i++) {
1364
+ result = results[i];
1365
+ this._eachEntry(result.entry, result.position);
1366
+ }
1367
+ };
1368
+
1369
+ var $$rsvp$hash$$default = function hash(object, label) {
1370
+ return new $$promise$hash$$default($$rsvp$promise$$default, object, label).promise;
1371
+ };
1372
+
1373
+ function $$rsvp$hash$settled$$HashSettled(Constructor, object, label) {
1374
+ this._superConstructor(Constructor, object, false, label);
1375
+ }
1376
+
1377
+ $$rsvp$hash$settled$$HashSettled.prototype = $$utils$$o_create($$promise$hash$$default.prototype);
1378
+ $$rsvp$hash$settled$$HashSettled.prototype._superConstructor = $$enumerator$$default;
1379
+ $$rsvp$hash$settled$$HashSettled.prototype._makeResult = $$enumerator$$makeSettledResult;
1380
+
1381
+ $$rsvp$hash$settled$$HashSettled.prototype._validationError = function() {
1382
+ return new Error('hashSettled must be called with an object');
1383
+ };
1384
+
1385
+ var $$rsvp$hash$settled$$default = function hashSettled(object, label) {
1386
+ return new $$rsvp$hash$settled$$HashSettled($$rsvp$promise$$default, object, label).promise;
1387
+ };
1388
+
1389
+ var $$rsvp$rethrow$$default = function rethrow(reason) {
1390
+ setTimeout(function() {
1391
+ throw reason;
1392
+ });
1393
+ throw reason;
1394
+ };
1395
+
1396
+ var $$rsvp$defer$$default = function defer(label) {
1397
+ var deferred = { };
1398
+
1399
+ deferred.promise = new $$rsvp$promise$$default(function(resolve, reject) {
1400
+ deferred.resolve = resolve;
1401
+ deferred.reject = reject;
1402
+ }, label);
1403
+
1404
+ return deferred;
1405
+ };
1406
+
1407
+ var $$rsvp$map$$default = function map(promises, mapFn, label) {
1408
+ return $$rsvp$promise$$default.all(promises, label).then(function(values) {
1409
+ if (!$$utils$$isFunction(mapFn)) {
1410
+ throw new TypeError("You must pass a function as map's second argument.");
1411
+ }
1412
+
1413
+ var length = values.length;
1414
+ var results = new Array(length);
1415
+
1416
+ for (var i = 0; i < length; i++) {
1417
+ results[i] = mapFn(values[i]);
1418
+ }
1419
+
1420
+ return $$rsvp$promise$$default.all(results, label);
1421
+ });
1422
+ };
1423
+
1424
+ var $$rsvp$resolve$$default = function resolve(value, label) {
1425
+ return $$rsvp$promise$$default.resolve(value, label);
1426
+ };
1427
+
1428
+ var $$rsvp$reject$$default = function reject(reason, label) {
1429
+ return $$rsvp$promise$$default.reject(reason, label);
1430
+ };
1431
+
1432
+ var $$rsvp$filter$$default = function filter(promises, filterFn, label) {
1433
+ return $$rsvp$promise$$default.all(promises, label).then(function(values) {
1434
+ if (!$$utils$$isFunction(filterFn)) {
1435
+ throw new TypeError("You must pass a function as filter's second argument.");
1436
+ }
1437
+
1438
+ var length = values.length;
1439
+ var filtered = new Array(length);
1440
+
1441
+ for (var i = 0; i < length; i++) {
1442
+ filtered[i] = filterFn(values[i]);
1443
+ }
1444
+
1445
+ return $$rsvp$promise$$default.all(filtered, label).then(function(filtered) {
1446
+ var results = new Array(length);
1447
+ var newLength = 0;
1448
+
1449
+ for (var i = 0; i < length; i++) {
1450
+ if (filtered[i]) {
1451
+ results[newLength] = values[i];
1452
+ newLength++;
1453
+ }
1454
+ }
1455
+
1456
+ results.length = newLength;
1457
+
1458
+ return results;
1459
+ });
1460
+ });
1461
+ };
1462
+
1463
+ var $$rsvp$asap$$len = 0;
1464
+
1465
+ var $$rsvp$asap$$default = function asap(callback, arg) {
1466
+ $$rsvp$asap$$queue[$$rsvp$asap$$len] = callback;
1467
+ $$rsvp$asap$$queue[$$rsvp$asap$$len + 1] = arg;
1468
+ $$rsvp$asap$$len += 2;
1469
+ if ($$rsvp$asap$$len === 2) {
1470
+ // If len is 1, that means that we need to schedule an async flush.
1471
+ // If additional callbacks are queued before the queue is flushed, they
1472
+ // will be processed by this flush that we are scheduling.
1473
+ $$rsvp$asap$$scheduleFlush();
1474
+ }
1475
+ };
1476
+
1477
+ var $$rsvp$asap$$browserGlobal = (typeof window !== 'undefined') ? window : {};
1478
+ var $$rsvp$asap$$BrowserMutationObserver = $$rsvp$asap$$browserGlobal.MutationObserver || $$rsvp$asap$$browserGlobal.WebKitMutationObserver;
1479
+
1480
+ // test for web worker but not in IE10
1481
+ var $$rsvp$asap$$isWorker = typeof Uint8ClampedArray !== 'undefined' &&
1482
+ typeof importScripts !== 'undefined' &&
1483
+ typeof MessageChannel !== 'undefined';
1484
+
1485
+ // node
1486
+ function $$rsvp$asap$$useNextTick() {
1487
+ return function() {
1488
+ process.nextTick($$rsvp$asap$$flush);
1489
+ };
1490
+ }
1491
+
1492
+ function $$rsvp$asap$$useMutationObserver() {
1493
+ var iterations = 0;
1494
+ var observer = new $$rsvp$asap$$BrowserMutationObserver($$rsvp$asap$$flush);
1495
+ var node = document.createTextNode('');
1496
+ observer.observe(node, { characterData: true });
1497
+
1498
+ return function() {
1499
+ node.data = (iterations = ++iterations % 2);
1500
+ };
1501
+ }
1502
+
1503
+ // web worker
1504
+ function $$rsvp$asap$$useMessageChannel() {
1505
+ var channel = new MessageChannel();
1506
+ channel.port1.onmessage = $$rsvp$asap$$flush;
1507
+ return function () {
1508
+ channel.port2.postMessage(0);
1509
+ };
1510
+ }
1511
+
1512
+ function $$rsvp$asap$$useSetTimeout() {
1513
+ return function() {
1514
+ setTimeout($$rsvp$asap$$flush, 1);
1515
+ };
1516
+ }
1517
+
1518
+ var $$rsvp$asap$$queue = new Array(1000);
1519
+
1520
+ function $$rsvp$asap$$flush() {
1521
+ for (var i = 0; i < $$rsvp$asap$$len; i+=2) {
1522
+ var callback = $$rsvp$asap$$queue[i];
1523
+ var arg = $$rsvp$asap$$queue[i+1];
1524
+
1525
+ callback(arg);
1526
+
1527
+ $$rsvp$asap$$queue[i] = undefined;
1528
+ $$rsvp$asap$$queue[i+1] = undefined;
1529
+ }
1530
+
1531
+ $$rsvp$asap$$len = 0;
1532
+ }
1533
+
1534
+ var $$rsvp$asap$$scheduleFlush;
1535
+
1536
+ // Decide what async method to use to triggering processing of queued callbacks:
1537
+ if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1538
+ $$rsvp$asap$$scheduleFlush = $$rsvp$asap$$useNextTick();
1539
+ } else if ($$rsvp$asap$$BrowserMutationObserver) {
1540
+ $$rsvp$asap$$scheduleFlush = $$rsvp$asap$$useMutationObserver();
1541
+ } else if ($$rsvp$asap$$isWorker) {
1542
+ $$rsvp$asap$$scheduleFlush = $$rsvp$asap$$useMessageChannel();
1543
+ } else {
1544
+ $$rsvp$asap$$scheduleFlush = $$rsvp$asap$$useSetTimeout();
1545
+ }
1546
+
1547
+ // default async is asap;
1548
+ $$rsvp$config$$config.async = $$rsvp$asap$$default;
1549
+
1550
+ var $$rsvp$$cast = $$rsvp$resolve$$default;
1551
+
1552
+ function $$rsvp$$async(callback, arg) {
1553
+ $$rsvp$config$$config.async(callback, arg);
1554
+ }
1555
+
1556
+ function $$rsvp$$on() {
1557
+ $$rsvp$config$$config.on.apply($$rsvp$config$$config, arguments);
1558
+ }
1559
+
1560
+ function $$rsvp$$off() {
1561
+ $$rsvp$config$$config.off.apply($$rsvp$config$$config, arguments);
1562
+ }
1563
+
1564
+ // Set up instrumentation through `window.__PROMISE_INTRUMENTATION__`
1565
+ if (typeof window !== 'undefined' && typeof window['__PROMISE_INSTRUMENTATION__'] === 'object') {
1566
+ var $$rsvp$$callbacks = window['__PROMISE_INSTRUMENTATION__'];
1567
+ $$rsvp$config$$configure('instrument', true);
1568
+ for (var $$rsvp$$eventName in $$rsvp$$callbacks) {
1569
+ if ($$rsvp$$callbacks.hasOwnProperty($$rsvp$$eventName)) {
1570
+ $$rsvp$$on($$rsvp$$eventName, $$rsvp$$callbacks[$$rsvp$$eventName]);
1571
+ }
1572
+ }
1573
+ }
1574
+
1575
+ var rsvp$umd$$RSVP = {
1576
+ 'race': $$rsvp$race$$default,
1577
+ 'Promise': $$rsvp$promise$$default,
1578
+ 'allSettled': $$rsvp$all$settled$$default,
1579
+ 'hash': $$rsvp$hash$$default,
1580
+ 'hashSettled': $$rsvp$hash$settled$$default,
1581
+ 'denodeify': $$rsvp$node$$default,
1582
+ 'on': $$rsvp$$on,
1583
+ 'off': $$rsvp$$off,
1584
+ 'map': $$rsvp$map$$default,
1585
+ 'filter': $$rsvp$filter$$default,
1586
+ 'resolve': $$rsvp$resolve$$default,
1587
+ 'reject': $$rsvp$reject$$default,
1588
+ 'all': $$rsvp$all$$default,
1589
+ 'rethrow': $$rsvp$rethrow$$default,
1590
+ 'defer': $$rsvp$defer$$default,
1591
+ 'EventTarget': $$rsvp$events$$default,
1592
+ 'configure': $$rsvp$config$$configure,
1593
+ 'async': $$rsvp$$async
1594
+ };
1595
+
1596
+ /* global define:true module:true window: true */
1597
+ if (typeof define === 'function' && define.amd) {
1598
+ define(function() { return rsvp$umd$$RSVP; });
1599
+ } else if (typeof module !== 'undefined' && module.exports) {
1600
+ module.exports = rsvp$umd$$RSVP;
1601
+ } else if (typeof this !== 'undefined') {
1602
+ this['RSVP'] = rsvp$umd$$RSVP;
1603
+ }
1604
+ }).call(this);