es6-promise-rails 1.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +15 -15
- data/README.md +1 -1
- data/lib/es6/promise/rails/version.rb +1 -1
- data/vendor/assets/javascripts/es6-promise.js +966 -0
- metadata +9 -9
- data/vendor/assets/javascripts/promise.js +0 -690
@@ -1,690 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* https://github.com/jakearchibald/es6-promise
|
3
|
-
*
|
4
|
-
* version: 1.0.0
|
5
|
-
*/
|
6
|
-
|
7
|
-
(function() {
|
8
|
-
var define, requireModule, require, requirejs;
|
9
|
-
|
10
|
-
(function() {
|
11
|
-
var registry = {}, seen = {};
|
12
|
-
|
13
|
-
define = function(name, deps, callback) {
|
14
|
-
registry[name] = { deps: deps, callback: callback };
|
15
|
-
};
|
16
|
-
|
17
|
-
requirejs = require = requireModule = function(name) {
|
18
|
-
requirejs._eak_seen = registry;
|
19
|
-
|
20
|
-
if (seen[name]) { return seen[name]; }
|
21
|
-
seen[name] = {};
|
22
|
-
|
23
|
-
if (!registry[name]) {
|
24
|
-
throw new Error("Could not find module " + name);
|
25
|
-
}
|
26
|
-
|
27
|
-
var mod = registry[name],
|
28
|
-
deps = mod.deps,
|
29
|
-
callback = mod.callback,
|
30
|
-
reified = [],
|
31
|
-
exports;
|
32
|
-
|
33
|
-
for (var i=0, l=deps.length; i<l; i++) {
|
34
|
-
if (deps[i] === 'exports') {
|
35
|
-
reified.push(exports = {});
|
36
|
-
} else {
|
37
|
-
reified.push(requireModule(resolve(deps[i])));
|
38
|
-
}
|
39
|
-
}
|
40
|
-
|
41
|
-
var value = callback.apply(this, reified);
|
42
|
-
return seen[name] = exports || value;
|
43
|
-
|
44
|
-
function resolve(child) {
|
45
|
-
if (child.charAt(0) !== '.') { return child; }
|
46
|
-
var parts = child.split("/");
|
47
|
-
var parentBase = name.split("/").slice(0, -1);
|
48
|
-
|
49
|
-
for (var i=0, l=parts.length; i<l; i++) {
|
50
|
-
var part = parts[i];
|
51
|
-
|
52
|
-
if (part === '..') { parentBase.pop(); }
|
53
|
-
else if (part === '.') { continue; }
|
54
|
-
else { parentBase.push(part); }
|
55
|
-
}
|
56
|
-
|
57
|
-
return parentBase.join("/");
|
58
|
-
}
|
59
|
-
};
|
60
|
-
})();
|
61
|
-
|
62
|
-
define("promise/all",
|
63
|
-
["./utils","exports"],
|
64
|
-
function(__dependency1__, __exports__) {
|
65
|
-
"use strict";
|
66
|
-
/* global toString */
|
67
|
-
|
68
|
-
var isArray = __dependency1__.isArray;
|
69
|
-
var isFunction = __dependency1__.isFunction;
|
70
|
-
|
71
|
-
/**
|
72
|
-
Returns a promise that is fulfilled when all the given promises have been
|
73
|
-
fulfilled, or rejected if any of them become rejected. The return promise
|
74
|
-
is fulfilled with an array that gives all the values in the order they were
|
75
|
-
passed in the `promises` array argument.
|
76
|
-
|
77
|
-
Example:
|
78
|
-
|
79
|
-
```javascript
|
80
|
-
var promise1 = RSVP.resolve(1);
|
81
|
-
var promise2 = RSVP.resolve(2);
|
82
|
-
var promise3 = RSVP.resolve(3);
|
83
|
-
var promises = [ promise1, promise2, promise3 ];
|
84
|
-
|
85
|
-
RSVP.all(promises).then(function(array){
|
86
|
-
// The array here would be [ 1, 2, 3 ];
|
87
|
-
});
|
88
|
-
```
|
89
|
-
|
90
|
-
If any of the `promises` given to `RSVP.all` are rejected, the first promise
|
91
|
-
that is rejected will be given as an argument to the returned promises's
|
92
|
-
rejection handler. For example:
|
93
|
-
|
94
|
-
Example:
|
95
|
-
|
96
|
-
```javascript
|
97
|
-
var promise1 = RSVP.resolve(1);
|
98
|
-
var promise2 = RSVP.reject(new Error("2"));
|
99
|
-
var promise3 = RSVP.reject(new Error("3"));
|
100
|
-
var promises = [ promise1, promise2, promise3 ];
|
101
|
-
|
102
|
-
RSVP.all(promises).then(function(array){
|
103
|
-
// Code here never runs because there are rejected promises!
|
104
|
-
}, function(error) {
|
105
|
-
// error.message === "2"
|
106
|
-
});
|
107
|
-
```
|
108
|
-
|
109
|
-
@method all
|
110
|
-
@for RSVP
|
111
|
-
@param {Array} promises
|
112
|
-
@param {String} label
|
113
|
-
@return {Promise} promise that is fulfilled when all `promises` have been
|
114
|
-
fulfilled, or rejected if any of them become rejected.
|
115
|
-
*/
|
116
|
-
function all(promises) {
|
117
|
-
/*jshint validthis:true */
|
118
|
-
var Promise = this;
|
119
|
-
|
120
|
-
if (!isArray(promises)) {
|
121
|
-
throw new TypeError('You must pass an array to all.');
|
122
|
-
}
|
123
|
-
|
124
|
-
return new Promise(function(resolve, reject) {
|
125
|
-
var results = [], remaining = promises.length,
|
126
|
-
promise;
|
127
|
-
|
128
|
-
if (remaining === 0) {
|
129
|
-
resolve([]);
|
130
|
-
}
|
131
|
-
|
132
|
-
function resolver(index) {
|
133
|
-
return function(value) {
|
134
|
-
resolveAll(index, value);
|
135
|
-
};
|
136
|
-
}
|
137
|
-
|
138
|
-
function resolveAll(index, value) {
|
139
|
-
results[index] = value;
|
140
|
-
if (--remaining === 0) {
|
141
|
-
resolve(results);
|
142
|
-
}
|
143
|
-
}
|
144
|
-
|
145
|
-
for (var i = 0; i < promises.length; i++) {
|
146
|
-
promise = promises[i];
|
147
|
-
|
148
|
-
if (promise && isFunction(promise.then)) {
|
149
|
-
promise.then(resolver(i), reject);
|
150
|
-
} else {
|
151
|
-
resolveAll(i, promise);
|
152
|
-
}
|
153
|
-
}
|
154
|
-
});
|
155
|
-
}
|
156
|
-
|
157
|
-
__exports__.all = all;
|
158
|
-
});
|
159
|
-
define("promise/asap",
|
160
|
-
["exports"],
|
161
|
-
function(__exports__) {
|
162
|
-
"use strict";
|
163
|
-
var browserGlobal = (typeof window !== 'undefined') ? window : {};
|
164
|
-
var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
|
165
|
-
var local = (typeof global !== 'undefined') ? global : (this === undefined? window:this);
|
166
|
-
|
167
|
-
// node
|
168
|
-
function useNextTick() {
|
169
|
-
return function() {
|
170
|
-
process.nextTick(flush);
|
171
|
-
};
|
172
|
-
}
|
173
|
-
|
174
|
-
function useMutationObserver() {
|
175
|
-
var iterations = 0;
|
176
|
-
var observer = new BrowserMutationObserver(flush);
|
177
|
-
var node = document.createTextNode('');
|
178
|
-
observer.observe(node, { characterData: true });
|
179
|
-
|
180
|
-
return function() {
|
181
|
-
node.data = (iterations = ++iterations % 2);
|
182
|
-
};
|
183
|
-
}
|
184
|
-
|
185
|
-
function useSetTimeout() {
|
186
|
-
return function() {
|
187
|
-
local.setTimeout(flush, 1);
|
188
|
-
};
|
189
|
-
}
|
190
|
-
|
191
|
-
var queue = [];
|
192
|
-
function flush() {
|
193
|
-
for (var i = 0; i < queue.length; i++) {
|
194
|
-
var tuple = queue[i];
|
195
|
-
var callback = tuple[0], arg = tuple[1];
|
196
|
-
callback(arg);
|
197
|
-
}
|
198
|
-
queue = [];
|
199
|
-
}
|
200
|
-
|
201
|
-
var scheduleFlush;
|
202
|
-
|
203
|
-
// Decide what async method to use to triggering processing of queued callbacks:
|
204
|
-
if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
|
205
|
-
scheduleFlush = useNextTick();
|
206
|
-
} else if (BrowserMutationObserver) {
|
207
|
-
scheduleFlush = useMutationObserver();
|
208
|
-
} else {
|
209
|
-
scheduleFlush = useSetTimeout();
|
210
|
-
}
|
211
|
-
|
212
|
-
function asap(callback, arg) {
|
213
|
-
var length = queue.push([callback, arg]);
|
214
|
-
if (length === 1) {
|
215
|
-
// If length is 1, that means that we need to schedule an async flush.
|
216
|
-
// If additional callbacks are queued before the queue is flushed, they
|
217
|
-
// will be processed by this flush that we are scheduling.
|
218
|
-
scheduleFlush();
|
219
|
-
}
|
220
|
-
}
|
221
|
-
|
222
|
-
__exports__.asap = asap;
|
223
|
-
});
|
224
|
-
define("promise/config",
|
225
|
-
["exports"],
|
226
|
-
function(__exports__) {
|
227
|
-
"use strict";
|
228
|
-
var config = {
|
229
|
-
instrument: false
|
230
|
-
};
|
231
|
-
|
232
|
-
function configure(name, value) {
|
233
|
-
if (arguments.length === 2) {
|
234
|
-
config[name] = value;
|
235
|
-
} else {
|
236
|
-
return config[name];
|
237
|
-
}
|
238
|
-
}
|
239
|
-
|
240
|
-
__exports__.config = config;
|
241
|
-
__exports__.configure = configure;
|
242
|
-
});
|
243
|
-
define("promise/polyfill",
|
244
|
-
["./promise","./utils","exports"],
|
245
|
-
function(__dependency1__, __dependency2__, __exports__) {
|
246
|
-
"use strict";
|
247
|
-
/*global self*/
|
248
|
-
var RSVPPromise = __dependency1__.Promise;
|
249
|
-
var isFunction = __dependency2__.isFunction;
|
250
|
-
|
251
|
-
function polyfill() {
|
252
|
-
var local;
|
253
|
-
|
254
|
-
if (typeof global !== 'undefined') {
|
255
|
-
local = global;
|
256
|
-
} else if (typeof window !== 'undefined' && window.document) {
|
257
|
-
local = window;
|
258
|
-
} else {
|
259
|
-
local = self;
|
260
|
-
}
|
261
|
-
|
262
|
-
var es6PromiseSupport =
|
263
|
-
"Promise" in local &&
|
264
|
-
// Some of these methods are missing from
|
265
|
-
// Firefox/Chrome experimental implementations
|
266
|
-
"resolve" in local.Promise &&
|
267
|
-
"reject" in local.Promise &&
|
268
|
-
"all" in local.Promise &&
|
269
|
-
"race" in local.Promise &&
|
270
|
-
// Older version of the spec had a resolver object
|
271
|
-
// as the arg rather than a function
|
272
|
-
(function() {
|
273
|
-
var resolve;
|
274
|
-
new local.Promise(function(r) { resolve = r; });
|
275
|
-
return isFunction(resolve);
|
276
|
-
}());
|
277
|
-
|
278
|
-
if (!es6PromiseSupport) {
|
279
|
-
local.Promise = RSVPPromise;
|
280
|
-
}
|
281
|
-
}
|
282
|
-
|
283
|
-
__exports__.polyfill = polyfill;
|
284
|
-
});
|
285
|
-
define("promise/promise",
|
286
|
-
["./config","./utils","./all","./race","./resolve","./reject","./asap","exports"],
|
287
|
-
function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __dependency7__, __exports__) {
|
288
|
-
"use strict";
|
289
|
-
var config = __dependency1__.config;
|
290
|
-
var configure = __dependency1__.configure;
|
291
|
-
var objectOrFunction = __dependency2__.objectOrFunction;
|
292
|
-
var isFunction = __dependency2__.isFunction;
|
293
|
-
var now = __dependency2__.now;
|
294
|
-
var all = __dependency3__.all;
|
295
|
-
var race = __dependency4__.race;
|
296
|
-
var staticResolve = __dependency5__.resolve;
|
297
|
-
var staticReject = __dependency6__.reject;
|
298
|
-
var asap = __dependency7__.asap;
|
299
|
-
|
300
|
-
var counter = 0;
|
301
|
-
|
302
|
-
config.async = asap; // default async is asap;
|
303
|
-
|
304
|
-
function Promise(resolver) {
|
305
|
-
if (!isFunction(resolver)) {
|
306
|
-
throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
|
307
|
-
}
|
308
|
-
|
309
|
-
if (!(this instanceof Promise)) {
|
310
|
-
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
|
311
|
-
}
|
312
|
-
|
313
|
-
this._subscribers = [];
|
314
|
-
|
315
|
-
invokeResolver(resolver, this);
|
316
|
-
}
|
317
|
-
|
318
|
-
function invokeResolver(resolver, promise) {
|
319
|
-
function resolvePromise(value) {
|
320
|
-
resolve(promise, value);
|
321
|
-
}
|
322
|
-
|
323
|
-
function rejectPromise(reason) {
|
324
|
-
reject(promise, reason);
|
325
|
-
}
|
326
|
-
|
327
|
-
try {
|
328
|
-
resolver(resolvePromise, rejectPromise);
|
329
|
-
} catch(e) {
|
330
|
-
rejectPromise(e);
|
331
|
-
}
|
332
|
-
}
|
333
|
-
|
334
|
-
function invokeCallback(settled, promise, callback, detail) {
|
335
|
-
var hasCallback = isFunction(callback),
|
336
|
-
value, error, succeeded, failed;
|
337
|
-
|
338
|
-
if (hasCallback) {
|
339
|
-
try {
|
340
|
-
value = callback(detail);
|
341
|
-
succeeded = true;
|
342
|
-
} catch(e) {
|
343
|
-
failed = true;
|
344
|
-
error = e;
|
345
|
-
}
|
346
|
-
} else {
|
347
|
-
value = detail;
|
348
|
-
succeeded = true;
|
349
|
-
}
|
350
|
-
|
351
|
-
if (handleThenable(promise, value)) {
|
352
|
-
return;
|
353
|
-
} else if (hasCallback && succeeded) {
|
354
|
-
resolve(promise, value);
|
355
|
-
} else if (failed) {
|
356
|
-
reject(promise, error);
|
357
|
-
} else if (settled === FULFILLED) {
|
358
|
-
resolve(promise, value);
|
359
|
-
} else if (settled === REJECTED) {
|
360
|
-
reject(promise, value);
|
361
|
-
}
|
362
|
-
}
|
363
|
-
|
364
|
-
var PENDING = void 0;
|
365
|
-
var SEALED = 0;
|
366
|
-
var FULFILLED = 1;
|
367
|
-
var REJECTED = 2;
|
368
|
-
|
369
|
-
function subscribe(parent, child, onFulfillment, onRejection) {
|
370
|
-
var subscribers = parent._subscribers;
|
371
|
-
var length = subscribers.length;
|
372
|
-
|
373
|
-
subscribers[length] = child;
|
374
|
-
subscribers[length + FULFILLED] = onFulfillment;
|
375
|
-
subscribers[length + REJECTED] = onRejection;
|
376
|
-
}
|
377
|
-
|
378
|
-
function publish(promise, settled) {
|
379
|
-
var child, callback, subscribers = promise._subscribers, detail = promise._detail;
|
380
|
-
|
381
|
-
for (var i = 0; i < subscribers.length; i += 3) {
|
382
|
-
child = subscribers[i];
|
383
|
-
callback = subscribers[i + settled];
|
384
|
-
|
385
|
-
invokeCallback(settled, child, callback, detail);
|
386
|
-
}
|
387
|
-
|
388
|
-
promise._subscribers = null;
|
389
|
-
}
|
390
|
-
|
391
|
-
Promise.prototype = {
|
392
|
-
constructor: Promise,
|
393
|
-
|
394
|
-
_state: undefined,
|
395
|
-
_detail: undefined,
|
396
|
-
_subscribers: undefined,
|
397
|
-
|
398
|
-
then: function(onFulfillment, onRejection) {
|
399
|
-
var promise = this;
|
400
|
-
|
401
|
-
var thenPromise = new this.constructor(function() {});
|
402
|
-
|
403
|
-
if (this._state) {
|
404
|
-
var callbacks = arguments;
|
405
|
-
config.async(function invokePromiseCallback() {
|
406
|
-
invokeCallback(promise._state, thenPromise, callbacks[promise._state - 1], promise._detail);
|
407
|
-
});
|
408
|
-
} else {
|
409
|
-
subscribe(this, thenPromise, onFulfillment, onRejection);
|
410
|
-
}
|
411
|
-
|
412
|
-
return thenPromise;
|
413
|
-
},
|
414
|
-
|
415
|
-
'catch': function(onRejection) {
|
416
|
-
return this.then(null, onRejection);
|
417
|
-
}
|
418
|
-
};
|
419
|
-
|
420
|
-
Promise.all = all;
|
421
|
-
Promise.race = race;
|
422
|
-
Promise.resolve = staticResolve;
|
423
|
-
Promise.reject = staticReject;
|
424
|
-
|
425
|
-
function handleThenable(promise, value) {
|
426
|
-
var then = null,
|
427
|
-
resolved;
|
428
|
-
|
429
|
-
try {
|
430
|
-
if (promise === value) {
|
431
|
-
throw new TypeError("A promises callback cannot return that same promise.");
|
432
|
-
}
|
433
|
-
|
434
|
-
if (objectOrFunction(value)) {
|
435
|
-
then = value.then;
|
436
|
-
|
437
|
-
if (isFunction(then)) {
|
438
|
-
then.call(value, function(val) {
|
439
|
-
if (resolved) { return true; }
|
440
|
-
resolved = true;
|
441
|
-
|
442
|
-
if (value !== val) {
|
443
|
-
resolve(promise, val);
|
444
|
-
} else {
|
445
|
-
fulfill(promise, val);
|
446
|
-
}
|
447
|
-
}, function(val) {
|
448
|
-
if (resolved) { return true; }
|
449
|
-
resolved = true;
|
450
|
-
|
451
|
-
reject(promise, val);
|
452
|
-
});
|
453
|
-
|
454
|
-
return true;
|
455
|
-
}
|
456
|
-
}
|
457
|
-
} catch (error) {
|
458
|
-
if (resolved) { return true; }
|
459
|
-
reject(promise, error);
|
460
|
-
return true;
|
461
|
-
}
|
462
|
-
|
463
|
-
return false;
|
464
|
-
}
|
465
|
-
|
466
|
-
function resolve(promise, value) {
|
467
|
-
if (promise === value) {
|
468
|
-
fulfill(promise, value);
|
469
|
-
} else if (!handleThenable(promise, value)) {
|
470
|
-
fulfill(promise, value);
|
471
|
-
}
|
472
|
-
}
|
473
|
-
|
474
|
-
function fulfill(promise, value) {
|
475
|
-
if (promise._state !== PENDING) { return; }
|
476
|
-
promise._state = SEALED;
|
477
|
-
promise._detail = value;
|
478
|
-
|
479
|
-
config.async(publishFulfillment, promise);
|
480
|
-
}
|
481
|
-
|
482
|
-
function reject(promise, reason) {
|
483
|
-
if (promise._state !== PENDING) { return; }
|
484
|
-
promise._state = SEALED;
|
485
|
-
promise._detail = reason;
|
486
|
-
|
487
|
-
config.async(publishRejection, promise);
|
488
|
-
}
|
489
|
-
|
490
|
-
function publishFulfillment(promise) {
|
491
|
-
publish(promise, promise._state = FULFILLED);
|
492
|
-
}
|
493
|
-
|
494
|
-
function publishRejection(promise) {
|
495
|
-
publish(promise, promise._state = REJECTED);
|
496
|
-
}
|
497
|
-
|
498
|
-
__exports__.Promise = Promise;
|
499
|
-
});
|
500
|
-
define("promise/race",
|
501
|
-
["./utils","exports"],
|
502
|
-
function(__dependency1__, __exports__) {
|
503
|
-
"use strict";
|
504
|
-
/* global toString */
|
505
|
-
var isArray = __dependency1__.isArray;
|
506
|
-
|
507
|
-
/**
|
508
|
-
`RSVP.race` allows you to watch a series of promises and act as soon as the
|
509
|
-
first promise given to the `promises` argument fulfills or rejects.
|
510
|
-
|
511
|
-
Example:
|
512
|
-
|
513
|
-
```javascript
|
514
|
-
var promise1 = new RSVP.Promise(function(resolve, reject){
|
515
|
-
setTimeout(function(){
|
516
|
-
resolve("promise 1");
|
517
|
-
}, 200);
|
518
|
-
});
|
519
|
-
|
520
|
-
var promise2 = new RSVP.Promise(function(resolve, reject){
|
521
|
-
setTimeout(function(){
|
522
|
-
resolve("promise 2");
|
523
|
-
}, 100);
|
524
|
-
});
|
525
|
-
|
526
|
-
RSVP.race([promise1, promise2]).then(function(result){
|
527
|
-
// result === "promise 2" because it was resolved before promise1
|
528
|
-
// was resolved.
|
529
|
-
});
|
530
|
-
```
|
531
|
-
|
532
|
-
`RSVP.race` is deterministic in that only the state of the first completed
|
533
|
-
promise matters. For example, even if other promises given to the `promises`
|
534
|
-
array argument are resolved, but the first completed promise has become
|
535
|
-
rejected before the other promises became fulfilled, the returned promise
|
536
|
-
will become rejected:
|
537
|
-
|
538
|
-
```javascript
|
539
|
-
var promise1 = new RSVP.Promise(function(resolve, reject){
|
540
|
-
setTimeout(function(){
|
541
|
-
resolve("promise 1");
|
542
|
-
}, 200);
|
543
|
-
});
|
544
|
-
|
545
|
-
var promise2 = new RSVP.Promise(function(resolve, reject){
|
546
|
-
setTimeout(function(){
|
547
|
-
reject(new Error("promise 2"));
|
548
|
-
}, 100);
|
549
|
-
});
|
550
|
-
|
551
|
-
RSVP.race([promise1, promise2]).then(function(result){
|
552
|
-
// Code here never runs because there are rejected promises!
|
553
|
-
}, function(reason){
|
554
|
-
// reason.message === "promise2" because promise 2 became rejected before
|
555
|
-
// promise 1 became fulfilled
|
556
|
-
});
|
557
|
-
```
|
558
|
-
|
559
|
-
@method race
|
560
|
-
@for RSVP
|
561
|
-
@param {Array} promises array of promises to observe
|
562
|
-
@param {String} label optional string for describing the promise returned.
|
563
|
-
Useful for tooling.
|
564
|
-
@return {Promise} a promise that becomes fulfilled with the value the first
|
565
|
-
completed promises is resolved with if the first completed promise was
|
566
|
-
fulfilled, or rejected with the reason that the first completed promise
|
567
|
-
was rejected with.
|
568
|
-
*/
|
569
|
-
function race(promises) {
|
570
|
-
/*jshint validthis:true */
|
571
|
-
var Promise = this;
|
572
|
-
|
573
|
-
if (!isArray(promises)) {
|
574
|
-
throw new TypeError('You must pass an array to race.');
|
575
|
-
}
|
576
|
-
return new Promise(function(resolve, reject) {
|
577
|
-
var results = [], promise;
|
578
|
-
|
579
|
-
for (var i = 0; i < promises.length; i++) {
|
580
|
-
promise = promises[i];
|
581
|
-
|
582
|
-
if (promise && typeof promise.then === 'function') {
|
583
|
-
promise.then(resolve, reject);
|
584
|
-
} else {
|
585
|
-
resolve(promise);
|
586
|
-
}
|
587
|
-
}
|
588
|
-
});
|
589
|
-
}
|
590
|
-
|
591
|
-
__exports__.race = race;
|
592
|
-
});
|
593
|
-
define("promise/reject",
|
594
|
-
["exports"],
|
595
|
-
function(__exports__) {
|
596
|
-
"use strict";
|
597
|
-
/**
|
598
|
-
`RSVP.reject` returns a promise that will become rejected with the passed
|
599
|
-
`reason`. `RSVP.reject` is essentially shorthand for the following:
|
600
|
-
|
601
|
-
```javascript
|
602
|
-
var promise = new RSVP.Promise(function(resolve, reject){
|
603
|
-
reject(new Error('WHOOPS'));
|
604
|
-
});
|
605
|
-
|
606
|
-
promise.then(function(value){
|
607
|
-
// Code here doesn't run because the promise is rejected!
|
608
|
-
}, function(reason){
|
609
|
-
// reason.message === 'WHOOPS'
|
610
|
-
});
|
611
|
-
```
|
612
|
-
|
613
|
-
Instead of writing the above, your code now simply becomes the following:
|
614
|
-
|
615
|
-
```javascript
|
616
|
-
var promise = RSVP.reject(new Error('WHOOPS'));
|
617
|
-
|
618
|
-
promise.then(function(value){
|
619
|
-
// Code here doesn't run because the promise is rejected!
|
620
|
-
}, function(reason){
|
621
|
-
// reason.message === 'WHOOPS'
|
622
|
-
});
|
623
|
-
```
|
624
|
-
|
625
|
-
@method reject
|
626
|
-
@for RSVP
|
627
|
-
@param {Any} reason value that the returned promise will be rejected with.
|
628
|
-
@param {String} label optional string for identifying the returned promise.
|
629
|
-
Useful for tooling.
|
630
|
-
@return {Promise} a promise that will become rejected with the given
|
631
|
-
`reason`.
|
632
|
-
*/
|
633
|
-
function reject(reason) {
|
634
|
-
/*jshint validthis:true */
|
635
|
-
var Promise = this;
|
636
|
-
|
637
|
-
return new Promise(function (resolve, reject) {
|
638
|
-
reject(reason);
|
639
|
-
});
|
640
|
-
}
|
641
|
-
|
642
|
-
__exports__.reject = reject;
|
643
|
-
});
|
644
|
-
define("promise/resolve",
|
645
|
-
["exports"],
|
646
|
-
function(__exports__) {
|
647
|
-
"use strict";
|
648
|
-
function resolve(value) {
|
649
|
-
/*jshint validthis:true */
|
650
|
-
if (value && typeof value === 'object' && value.constructor === this) {
|
651
|
-
return value;
|
652
|
-
}
|
653
|
-
|
654
|
-
var Promise = this;
|
655
|
-
|
656
|
-
return new Promise(function(resolve) {
|
657
|
-
resolve(value);
|
658
|
-
});
|
659
|
-
}
|
660
|
-
|
661
|
-
__exports__.resolve = resolve;
|
662
|
-
});
|
663
|
-
define("promise/utils",
|
664
|
-
["exports"],
|
665
|
-
function(__exports__) {
|
666
|
-
"use strict";
|
667
|
-
function objectOrFunction(x) {
|
668
|
-
return isFunction(x) || (typeof x === "object" && x !== null);
|
669
|
-
}
|
670
|
-
|
671
|
-
function isFunction(x) {
|
672
|
-
return typeof x === "function";
|
673
|
-
}
|
674
|
-
|
675
|
-
function isArray(x) {
|
676
|
-
return Object.prototype.toString.call(x) === "[object Array]";
|
677
|
-
}
|
678
|
-
|
679
|
-
// Date.now is not available in browsers < IE9
|
680
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now#Compatibility
|
681
|
-
var now = Date.now || function() { return new Date().getTime(); };
|
682
|
-
|
683
|
-
|
684
|
-
__exports__.objectOrFunction = objectOrFunction;
|
685
|
-
__exports__.isFunction = isFunction;
|
686
|
-
__exports__.isArray = isArray;
|
687
|
-
__exports__.now = now;
|
688
|
-
});
|
689
|
-
requireModule('promise/polyfill').polyfill();
|
690
|
-
}());
|