es6-promise-rails 2.0.2.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +1 -1
- data/lib/es6/promise/rails/version.rb +1 -1
- data/vendor/assets/javascripts/promise.js +956 -0
- metadata +5 -5
- data/Gemfile.lock +0 -48
- data/vendor/assets/javascripts/es6-promise.js +0 -960
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 484b21e7738d8d921301870b14120dbcd0f94a62
|
4
|
+
data.tar.gz: 3bb7a4190adcafcdab802684fe2e1d102a7accf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90263488315c4d6944551a805f9606cab1d0783d30c196f71bbbeea11ff7447d33a3d4fadb7cd4a0a41b183f9c4409816e4355aa845be80b4709dff56cead63f
|
7
|
+
data.tar.gz: 8bfa2898d29357eac3a1a7c69498f7059a6bdff31c2dd591b358cab43be32b56d74cf32e1d6c909738d7253be946c2e85cac440d7750521d20aa0d14fe532a37
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -0,0 +1,956 @@
|
|
1
|
+
/*!
|
2
|
+
* @overview es6-promise - a tiny implementation of Promises/A+.
|
3
|
+
* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
|
4
|
+
* @license Licensed under MIT license
|
5
|
+
* See https://raw.githubusercontent.com/jakearchibald/es6-promise/master/LICENSE
|
6
|
+
* @version 2.1.0
|
7
|
+
*/
|
8
|
+
|
9
|
+
(function() {
|
10
|
+
"use strict";
|
11
|
+
function lib$es6$promise$utils$$objectOrFunction(x) {
|
12
|
+
return typeof x === 'function' || (typeof x === 'object' && x !== null);
|
13
|
+
}
|
14
|
+
|
15
|
+
function lib$es6$promise$utils$$isFunction(x) {
|
16
|
+
return typeof x === 'function';
|
17
|
+
}
|
18
|
+
|
19
|
+
function lib$es6$promise$utils$$isMaybeThenable(x) {
|
20
|
+
return typeof x === 'object' && x !== null;
|
21
|
+
}
|
22
|
+
|
23
|
+
var lib$es6$promise$utils$$_isArray;
|
24
|
+
if (!Array.isArray) {
|
25
|
+
lib$es6$promise$utils$$_isArray = function (x) {
|
26
|
+
return Object.prototype.toString.call(x) === '[object Array]';
|
27
|
+
};
|
28
|
+
} else {
|
29
|
+
lib$es6$promise$utils$$_isArray = Array.isArray;
|
30
|
+
}
|
31
|
+
|
32
|
+
var lib$es6$promise$utils$$isArray = lib$es6$promise$utils$$_isArray;
|
33
|
+
var lib$es6$promise$asap$$len = 0;
|
34
|
+
var lib$es6$promise$asap$$toString = {}.toString;
|
35
|
+
var lib$es6$promise$asap$$vertxNext;
|
36
|
+
function lib$es6$promise$asap$$asap(callback, arg) {
|
37
|
+
lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len] = callback;
|
38
|
+
lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len + 1] = arg;
|
39
|
+
lib$es6$promise$asap$$len += 2;
|
40
|
+
if (lib$es6$promise$asap$$len === 2) {
|
41
|
+
// If len is 2, that means that we need to schedule an async flush.
|
42
|
+
// If additional callbacks are queued before the queue is flushed, they
|
43
|
+
// will be processed by this flush that we are scheduling.
|
44
|
+
lib$es6$promise$asap$$scheduleFlush();
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
var lib$es6$promise$asap$$default = lib$es6$promise$asap$$asap;
|
49
|
+
|
50
|
+
var lib$es6$promise$asap$$browserWindow = (typeof window !== 'undefined') ? window : undefined;
|
51
|
+
var lib$es6$promise$asap$$browserGlobal = lib$es6$promise$asap$$browserWindow || {};
|
52
|
+
var lib$es6$promise$asap$$BrowserMutationObserver = lib$es6$promise$asap$$browserGlobal.MutationObserver || lib$es6$promise$asap$$browserGlobal.WebKitMutationObserver;
|
53
|
+
var lib$es6$promise$asap$$isNode = typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
|
54
|
+
|
55
|
+
// test for web worker but not in IE10
|
56
|
+
var lib$es6$promise$asap$$isWorker = typeof Uint8ClampedArray !== 'undefined' &&
|
57
|
+
typeof importScripts !== 'undefined' &&
|
58
|
+
typeof MessageChannel !== 'undefined';
|
59
|
+
|
60
|
+
// node
|
61
|
+
function lib$es6$promise$asap$$useNextTick() {
|
62
|
+
var nextTick = process.nextTick;
|
63
|
+
// node version 0.10.x displays a deprecation warning when nextTick is used recursively
|
64
|
+
// setImmediate should be used instead instead
|
65
|
+
var version = process.versions.node.match(/^(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)$/);
|
66
|
+
if (Array.isArray(version) && version[1] === '0' && version[2] === '10') {
|
67
|
+
nextTick = setImmediate;
|
68
|
+
}
|
69
|
+
return function() {
|
70
|
+
nextTick(lib$es6$promise$asap$$flush);
|
71
|
+
};
|
72
|
+
}
|
73
|
+
|
74
|
+
// vertx
|
75
|
+
function lib$es6$promise$asap$$useVertxTimer() {
|
76
|
+
return function() {
|
77
|
+
lib$es6$promise$asap$$vertxNext(lib$es6$promise$asap$$flush);
|
78
|
+
};
|
79
|
+
}
|
80
|
+
|
81
|
+
function lib$es6$promise$asap$$useMutationObserver() {
|
82
|
+
var iterations = 0;
|
83
|
+
var observer = new lib$es6$promise$asap$$BrowserMutationObserver(lib$es6$promise$asap$$flush);
|
84
|
+
var node = document.createTextNode('');
|
85
|
+
observer.observe(node, { characterData: true });
|
86
|
+
|
87
|
+
return function() {
|
88
|
+
node.data = (iterations = ++iterations % 2);
|
89
|
+
};
|
90
|
+
}
|
91
|
+
|
92
|
+
// web worker
|
93
|
+
function lib$es6$promise$asap$$useMessageChannel() {
|
94
|
+
var channel = new MessageChannel();
|
95
|
+
channel.port1.onmessage = lib$es6$promise$asap$$flush;
|
96
|
+
return function () {
|
97
|
+
channel.port2.postMessage(0);
|
98
|
+
};
|
99
|
+
}
|
100
|
+
|
101
|
+
function lib$es6$promise$asap$$useSetTimeout() {
|
102
|
+
return function() {
|
103
|
+
setTimeout(lib$es6$promise$asap$$flush, 1);
|
104
|
+
};
|
105
|
+
}
|
106
|
+
|
107
|
+
var lib$es6$promise$asap$$queue = new Array(1000);
|
108
|
+
function lib$es6$promise$asap$$flush() {
|
109
|
+
for (var i = 0; i < lib$es6$promise$asap$$len; i+=2) {
|
110
|
+
var callback = lib$es6$promise$asap$$queue[i];
|
111
|
+
var arg = lib$es6$promise$asap$$queue[i+1];
|
112
|
+
|
113
|
+
callback(arg);
|
114
|
+
|
115
|
+
lib$es6$promise$asap$$queue[i] = undefined;
|
116
|
+
lib$es6$promise$asap$$queue[i+1] = undefined;
|
117
|
+
}
|
118
|
+
|
119
|
+
lib$es6$promise$asap$$len = 0;
|
120
|
+
}
|
121
|
+
|
122
|
+
function lib$es6$promise$asap$$attemptVertex() {
|
123
|
+
try {
|
124
|
+
var r = require;
|
125
|
+
var vertx = r('vertx');
|
126
|
+
lib$es6$promise$asap$$vertxNext = vertx.runOnLoop || vertx.runOnContext;
|
127
|
+
return lib$es6$promise$asap$$useVertxTimer();
|
128
|
+
} catch(e) {
|
129
|
+
return lib$es6$promise$asap$$useSetTimeout();
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
var lib$es6$promise$asap$$scheduleFlush;
|
134
|
+
// Decide what async method to use to triggering processing of queued callbacks:
|
135
|
+
if (lib$es6$promise$asap$$isNode) {
|
136
|
+
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useNextTick();
|
137
|
+
} else if (lib$es6$promise$asap$$BrowserMutationObserver) {
|
138
|
+
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMutationObserver();
|
139
|
+
} else if (lib$es6$promise$asap$$isWorker) {
|
140
|
+
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMessageChannel();
|
141
|
+
} else if (lib$es6$promise$asap$$browserWindow === undefined && typeof require === 'function') {
|
142
|
+
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$attemptVertex();
|
143
|
+
} else {
|
144
|
+
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useSetTimeout();
|
145
|
+
}
|
146
|
+
|
147
|
+
function lib$es6$promise$$internal$$noop() {}
|
148
|
+
|
149
|
+
var lib$es6$promise$$internal$$PENDING = void 0;
|
150
|
+
var lib$es6$promise$$internal$$FULFILLED = 1;
|
151
|
+
var lib$es6$promise$$internal$$REJECTED = 2;
|
152
|
+
|
153
|
+
var lib$es6$promise$$internal$$GET_THEN_ERROR = new lib$es6$promise$$internal$$ErrorObject();
|
154
|
+
|
155
|
+
function lib$es6$promise$$internal$$selfFullfillment() {
|
156
|
+
return new TypeError("You cannot resolve a promise with itself");
|
157
|
+
}
|
158
|
+
|
159
|
+
function lib$es6$promise$$internal$$cannotReturnOwn() {
|
160
|
+
return new TypeError('A promises callback cannot return that same promise.');
|
161
|
+
}
|
162
|
+
|
163
|
+
function lib$es6$promise$$internal$$getThen(promise) {
|
164
|
+
try {
|
165
|
+
return promise.then;
|
166
|
+
} catch(error) {
|
167
|
+
lib$es6$promise$$internal$$GET_THEN_ERROR.error = error;
|
168
|
+
return lib$es6$promise$$internal$$GET_THEN_ERROR;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
|
172
|
+
function lib$es6$promise$$internal$$tryThen(then, value, fulfillmentHandler, rejectionHandler) {
|
173
|
+
try {
|
174
|
+
then.call(value, fulfillmentHandler, rejectionHandler);
|
175
|
+
} catch(e) {
|
176
|
+
return e;
|
177
|
+
}
|
178
|
+
}
|
179
|
+
|
180
|
+
function lib$es6$promise$$internal$$handleForeignThenable(promise, thenable, then) {
|
181
|
+
lib$es6$promise$asap$$default(function(promise) {
|
182
|
+
var sealed = false;
|
183
|
+
var error = lib$es6$promise$$internal$$tryThen(then, thenable, function(value) {
|
184
|
+
if (sealed) { return; }
|
185
|
+
sealed = true;
|
186
|
+
if (thenable !== value) {
|
187
|
+
lib$es6$promise$$internal$$resolve(promise, value);
|
188
|
+
} else {
|
189
|
+
lib$es6$promise$$internal$$fulfill(promise, value);
|
190
|
+
}
|
191
|
+
}, function(reason) {
|
192
|
+
if (sealed) { return; }
|
193
|
+
sealed = true;
|
194
|
+
|
195
|
+
lib$es6$promise$$internal$$reject(promise, reason);
|
196
|
+
}, 'Settle: ' + (promise._label || ' unknown promise'));
|
197
|
+
|
198
|
+
if (!sealed && error) {
|
199
|
+
sealed = true;
|
200
|
+
lib$es6$promise$$internal$$reject(promise, error);
|
201
|
+
}
|
202
|
+
}, promise);
|
203
|
+
}
|
204
|
+
|
205
|
+
function lib$es6$promise$$internal$$handleOwnThenable(promise, thenable) {
|
206
|
+
if (thenable._state === lib$es6$promise$$internal$$FULFILLED) {
|
207
|
+
lib$es6$promise$$internal$$fulfill(promise, thenable._result);
|
208
|
+
} else if (promise._state === lib$es6$promise$$internal$$REJECTED) {
|
209
|
+
lib$es6$promise$$internal$$reject(promise, thenable._result);
|
210
|
+
} else {
|
211
|
+
lib$es6$promise$$internal$$subscribe(thenable, undefined, function(value) {
|
212
|
+
lib$es6$promise$$internal$$resolve(promise, value);
|
213
|
+
}, function(reason) {
|
214
|
+
lib$es6$promise$$internal$$reject(promise, reason);
|
215
|
+
});
|
216
|
+
}
|
217
|
+
}
|
218
|
+
|
219
|
+
function lib$es6$promise$$internal$$handleMaybeThenable(promise, maybeThenable) {
|
220
|
+
if (maybeThenable.constructor === promise.constructor) {
|
221
|
+
lib$es6$promise$$internal$$handleOwnThenable(promise, maybeThenable);
|
222
|
+
} else {
|
223
|
+
var then = lib$es6$promise$$internal$$getThen(maybeThenable);
|
224
|
+
|
225
|
+
if (then === lib$es6$promise$$internal$$GET_THEN_ERROR) {
|
226
|
+
lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$GET_THEN_ERROR.error);
|
227
|
+
} else if (then === undefined) {
|
228
|
+
lib$es6$promise$$internal$$fulfill(promise, maybeThenable);
|
229
|
+
} else if (lib$es6$promise$utils$$isFunction(then)) {
|
230
|
+
lib$es6$promise$$internal$$handleForeignThenable(promise, maybeThenable, then);
|
231
|
+
} else {
|
232
|
+
lib$es6$promise$$internal$$fulfill(promise, maybeThenable);
|
233
|
+
}
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
237
|
+
function lib$es6$promise$$internal$$resolve(promise, value) {
|
238
|
+
if (promise === value) {
|
239
|
+
lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$selfFullfillment());
|
240
|
+
} else if (lib$es6$promise$utils$$objectOrFunction(value)) {
|
241
|
+
lib$es6$promise$$internal$$handleMaybeThenable(promise, value);
|
242
|
+
} else {
|
243
|
+
lib$es6$promise$$internal$$fulfill(promise, value);
|
244
|
+
}
|
245
|
+
}
|
246
|
+
|
247
|
+
function lib$es6$promise$$internal$$publishRejection(promise) {
|
248
|
+
if (promise._onerror) {
|
249
|
+
promise._onerror(promise._result);
|
250
|
+
}
|
251
|
+
|
252
|
+
lib$es6$promise$$internal$$publish(promise);
|
253
|
+
}
|
254
|
+
|
255
|
+
function lib$es6$promise$$internal$$fulfill(promise, value) {
|
256
|
+
if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; }
|
257
|
+
|
258
|
+
promise._result = value;
|
259
|
+
promise._state = lib$es6$promise$$internal$$FULFILLED;
|
260
|
+
|
261
|
+
if (promise._subscribers.length !== 0) {
|
262
|
+
lib$es6$promise$asap$$default(lib$es6$promise$$internal$$publish, promise);
|
263
|
+
}
|
264
|
+
}
|
265
|
+
|
266
|
+
function lib$es6$promise$$internal$$reject(promise, reason) {
|
267
|
+
if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; }
|
268
|
+
promise._state = lib$es6$promise$$internal$$REJECTED;
|
269
|
+
promise._result = reason;
|
270
|
+
|
271
|
+
lib$es6$promise$asap$$default(lib$es6$promise$$internal$$publishRejection, promise);
|
272
|
+
}
|
273
|
+
|
274
|
+
function lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection) {
|
275
|
+
var subscribers = parent._subscribers;
|
276
|
+
var length = subscribers.length;
|
277
|
+
|
278
|
+
parent._onerror = null;
|
279
|
+
|
280
|
+
subscribers[length] = child;
|
281
|
+
subscribers[length + lib$es6$promise$$internal$$FULFILLED] = onFulfillment;
|
282
|
+
subscribers[length + lib$es6$promise$$internal$$REJECTED] = onRejection;
|
283
|
+
|
284
|
+
if (length === 0 && parent._state) {
|
285
|
+
lib$es6$promise$asap$$default(lib$es6$promise$$internal$$publish, parent);
|
286
|
+
}
|
287
|
+
}
|
288
|
+
|
289
|
+
function lib$es6$promise$$internal$$publish(promise) {
|
290
|
+
var subscribers = promise._subscribers;
|
291
|
+
var settled = promise._state;
|
292
|
+
|
293
|
+
if (subscribers.length === 0) { return; }
|
294
|
+
|
295
|
+
var child, callback, detail = promise._result;
|
296
|
+
|
297
|
+
for (var i = 0; i < subscribers.length; i += 3) {
|
298
|
+
child = subscribers[i];
|
299
|
+
callback = subscribers[i + settled];
|
300
|
+
|
301
|
+
if (child) {
|
302
|
+
lib$es6$promise$$internal$$invokeCallback(settled, child, callback, detail);
|
303
|
+
} else {
|
304
|
+
callback(detail);
|
305
|
+
}
|
306
|
+
}
|
307
|
+
|
308
|
+
promise._subscribers.length = 0;
|
309
|
+
}
|
310
|
+
|
311
|
+
function lib$es6$promise$$internal$$ErrorObject() {
|
312
|
+
this.error = null;
|
313
|
+
}
|
314
|
+
|
315
|
+
var lib$es6$promise$$internal$$TRY_CATCH_ERROR = new lib$es6$promise$$internal$$ErrorObject();
|
316
|
+
|
317
|
+
function lib$es6$promise$$internal$$tryCatch(callback, detail) {
|
318
|
+
try {
|
319
|
+
return callback(detail);
|
320
|
+
} catch(e) {
|
321
|
+
lib$es6$promise$$internal$$TRY_CATCH_ERROR.error = e;
|
322
|
+
return lib$es6$promise$$internal$$TRY_CATCH_ERROR;
|
323
|
+
}
|
324
|
+
}
|
325
|
+
|
326
|
+
function lib$es6$promise$$internal$$invokeCallback(settled, promise, callback, detail) {
|
327
|
+
var hasCallback = lib$es6$promise$utils$$isFunction(callback),
|
328
|
+
value, error, succeeded, failed;
|
329
|
+
|
330
|
+
if (hasCallback) {
|
331
|
+
value = lib$es6$promise$$internal$$tryCatch(callback, detail);
|
332
|
+
|
333
|
+
if (value === lib$es6$promise$$internal$$TRY_CATCH_ERROR) {
|
334
|
+
failed = true;
|
335
|
+
error = value.error;
|
336
|
+
value = null;
|
337
|
+
} else {
|
338
|
+
succeeded = true;
|
339
|
+
}
|
340
|
+
|
341
|
+
if (promise === value) {
|
342
|
+
lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$cannotReturnOwn());
|
343
|
+
return;
|
344
|
+
}
|
345
|
+
|
346
|
+
} else {
|
347
|
+
value = detail;
|
348
|
+
succeeded = true;
|
349
|
+
}
|
350
|
+
|
351
|
+
if (promise._state !== lib$es6$promise$$internal$$PENDING) {
|
352
|
+
// noop
|
353
|
+
} else if (hasCallback && succeeded) {
|
354
|
+
lib$es6$promise$$internal$$resolve(promise, value);
|
355
|
+
} else if (failed) {
|
356
|
+
lib$es6$promise$$internal$$reject(promise, error);
|
357
|
+
} else if (settled === lib$es6$promise$$internal$$FULFILLED) {
|
358
|
+
lib$es6$promise$$internal$$fulfill(promise, value);
|
359
|
+
} else if (settled === lib$es6$promise$$internal$$REJECTED) {
|
360
|
+
lib$es6$promise$$internal$$reject(promise, value);
|
361
|
+
}
|
362
|
+
}
|
363
|
+
|
364
|
+
function lib$es6$promise$$internal$$initializePromise(promise, resolver) {
|
365
|
+
try {
|
366
|
+
resolver(function resolvePromise(value){
|
367
|
+
lib$es6$promise$$internal$$resolve(promise, value);
|
368
|
+
}, function rejectPromise(reason) {
|
369
|
+
lib$es6$promise$$internal$$reject(promise, reason);
|
370
|
+
});
|
371
|
+
} catch(e) {
|
372
|
+
lib$es6$promise$$internal$$reject(promise, e);
|
373
|
+
}
|
374
|
+
}
|
375
|
+
|
376
|
+
function lib$es6$promise$enumerator$$Enumerator(Constructor, input) {
|
377
|
+
var enumerator = this;
|
378
|
+
|
379
|
+
enumerator._instanceConstructor = Constructor;
|
380
|
+
enumerator.promise = new Constructor(lib$es6$promise$$internal$$noop);
|
381
|
+
|
382
|
+
if (enumerator._validateInput(input)) {
|
383
|
+
enumerator._input = input;
|
384
|
+
enumerator.length = input.length;
|
385
|
+
enumerator._remaining = input.length;
|
386
|
+
|
387
|
+
enumerator._init();
|
388
|
+
|
389
|
+
if (enumerator.length === 0) {
|
390
|
+
lib$es6$promise$$internal$$fulfill(enumerator.promise, enumerator._result);
|
391
|
+
} else {
|
392
|
+
enumerator.length = enumerator.length || 0;
|
393
|
+
enumerator._enumerate();
|
394
|
+
if (enumerator._remaining === 0) {
|
395
|
+
lib$es6$promise$$internal$$fulfill(enumerator.promise, enumerator._result);
|
396
|
+
}
|
397
|
+
}
|
398
|
+
} else {
|
399
|
+
lib$es6$promise$$internal$$reject(enumerator.promise, enumerator._validationError());
|
400
|
+
}
|
401
|
+
}
|
402
|
+
|
403
|
+
lib$es6$promise$enumerator$$Enumerator.prototype._validateInput = function(input) {
|
404
|
+
return lib$es6$promise$utils$$isArray(input);
|
405
|
+
};
|
406
|
+
|
407
|
+
lib$es6$promise$enumerator$$Enumerator.prototype._validationError = function() {
|
408
|
+
return new Error('Array Methods must be provided an Array');
|
409
|
+
};
|
410
|
+
|
411
|
+
lib$es6$promise$enumerator$$Enumerator.prototype._init = function() {
|
412
|
+
this._result = new Array(this.length);
|
413
|
+
};
|
414
|
+
|
415
|
+
var lib$es6$promise$enumerator$$default = lib$es6$promise$enumerator$$Enumerator;
|
416
|
+
|
417
|
+
lib$es6$promise$enumerator$$Enumerator.prototype._enumerate = function() {
|
418
|
+
var enumerator = this;
|
419
|
+
|
420
|
+
var length = enumerator.length;
|
421
|
+
var promise = enumerator.promise;
|
422
|
+
var input = enumerator._input;
|
423
|
+
|
424
|
+
for (var i = 0; promise._state === lib$es6$promise$$internal$$PENDING && i < length; i++) {
|
425
|
+
enumerator._eachEntry(input[i], i);
|
426
|
+
}
|
427
|
+
};
|
428
|
+
|
429
|
+
lib$es6$promise$enumerator$$Enumerator.prototype._eachEntry = function(entry, i) {
|
430
|
+
var enumerator = this;
|
431
|
+
var c = enumerator._instanceConstructor;
|
432
|
+
|
433
|
+
if (lib$es6$promise$utils$$isMaybeThenable(entry)) {
|
434
|
+
if (entry.constructor === c && entry._state !== lib$es6$promise$$internal$$PENDING) {
|
435
|
+
entry._onerror = null;
|
436
|
+
enumerator._settledAt(entry._state, i, entry._result);
|
437
|
+
} else {
|
438
|
+
enumerator._willSettleAt(c.resolve(entry), i);
|
439
|
+
}
|
440
|
+
} else {
|
441
|
+
enumerator._remaining--;
|
442
|
+
enumerator._result[i] = entry;
|
443
|
+
}
|
444
|
+
};
|
445
|
+
|
446
|
+
lib$es6$promise$enumerator$$Enumerator.prototype._settledAt = function(state, i, value) {
|
447
|
+
var enumerator = this;
|
448
|
+
var promise = enumerator.promise;
|
449
|
+
|
450
|
+
if (promise._state === lib$es6$promise$$internal$$PENDING) {
|
451
|
+
enumerator._remaining--;
|
452
|
+
|
453
|
+
if (state === lib$es6$promise$$internal$$REJECTED) {
|
454
|
+
lib$es6$promise$$internal$$reject(promise, value);
|
455
|
+
} else {
|
456
|
+
enumerator._result[i] = value;
|
457
|
+
}
|
458
|
+
}
|
459
|
+
|
460
|
+
if (enumerator._remaining === 0) {
|
461
|
+
lib$es6$promise$$internal$$fulfill(promise, enumerator._result);
|
462
|
+
}
|
463
|
+
};
|
464
|
+
|
465
|
+
lib$es6$promise$enumerator$$Enumerator.prototype._willSettleAt = function(promise, i) {
|
466
|
+
var enumerator = this;
|
467
|
+
|
468
|
+
lib$es6$promise$$internal$$subscribe(promise, undefined, function(value) {
|
469
|
+
enumerator._settledAt(lib$es6$promise$$internal$$FULFILLED, i, value);
|
470
|
+
}, function(reason) {
|
471
|
+
enumerator._settledAt(lib$es6$promise$$internal$$REJECTED, i, reason);
|
472
|
+
});
|
473
|
+
};
|
474
|
+
function lib$es6$promise$promise$all$$all(entries) {
|
475
|
+
return new lib$es6$promise$enumerator$$default(this, entries).promise;
|
476
|
+
}
|
477
|
+
var lib$es6$promise$promise$all$$default = lib$es6$promise$promise$all$$all;
|
478
|
+
function lib$es6$promise$promise$race$$race(entries) {
|
479
|
+
/*jshint validthis:true */
|
480
|
+
var Constructor = this;
|
481
|
+
|
482
|
+
var promise = new Constructor(lib$es6$promise$$internal$$noop);
|
483
|
+
|
484
|
+
if (!lib$es6$promise$utils$$isArray(entries)) {
|
485
|
+
lib$es6$promise$$internal$$reject(promise, new TypeError('You must pass an array to race.'));
|
486
|
+
return promise;
|
487
|
+
}
|
488
|
+
|
489
|
+
var length = entries.length;
|
490
|
+
|
491
|
+
function onFulfillment(value) {
|
492
|
+
lib$es6$promise$$internal$$resolve(promise, value);
|
493
|
+
}
|
494
|
+
|
495
|
+
function onRejection(reason) {
|
496
|
+
lib$es6$promise$$internal$$reject(promise, reason);
|
497
|
+
}
|
498
|
+
|
499
|
+
for (var i = 0; promise._state === lib$es6$promise$$internal$$PENDING && i < length; i++) {
|
500
|
+
lib$es6$promise$$internal$$subscribe(Constructor.resolve(entries[i]), undefined, onFulfillment, onRejection);
|
501
|
+
}
|
502
|
+
|
503
|
+
return promise;
|
504
|
+
}
|
505
|
+
var lib$es6$promise$promise$race$$default = lib$es6$promise$promise$race$$race;
|
506
|
+
function lib$es6$promise$promise$resolve$$resolve(object) {
|
507
|
+
/*jshint validthis:true */
|
508
|
+
var Constructor = this;
|
509
|
+
|
510
|
+
if (object && typeof object === 'object' && object.constructor === Constructor) {
|
511
|
+
return object;
|
512
|
+
}
|
513
|
+
|
514
|
+
var promise = new Constructor(lib$es6$promise$$internal$$noop);
|
515
|
+
lib$es6$promise$$internal$$resolve(promise, object);
|
516
|
+
return promise;
|
517
|
+
}
|
518
|
+
var lib$es6$promise$promise$resolve$$default = lib$es6$promise$promise$resolve$$resolve;
|
519
|
+
function lib$es6$promise$promise$reject$$reject(reason) {
|
520
|
+
/*jshint validthis:true */
|
521
|
+
var Constructor = this;
|
522
|
+
var promise = new Constructor(lib$es6$promise$$internal$$noop);
|
523
|
+
lib$es6$promise$$internal$$reject(promise, reason);
|
524
|
+
return promise;
|
525
|
+
}
|
526
|
+
var lib$es6$promise$promise$reject$$default = lib$es6$promise$promise$reject$$reject;
|
527
|
+
|
528
|
+
var lib$es6$promise$promise$$counter = 0;
|
529
|
+
|
530
|
+
function lib$es6$promise$promise$$needsResolver() {
|
531
|
+
throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
|
532
|
+
}
|
533
|
+
|
534
|
+
function lib$es6$promise$promise$$needsNew() {
|
535
|
+
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
|
536
|
+
}
|
537
|
+
|
538
|
+
var lib$es6$promise$promise$$default = lib$es6$promise$promise$$Promise;
|
539
|
+
/**
|
540
|
+
Promise objects represent the eventual result of an asynchronous operation. The
|
541
|
+
primary way of interacting with a promise is through its `then` method, which
|
542
|
+
registers callbacks to receive either a promise’s eventual value or the reason
|
543
|
+
why the promise cannot be fulfilled.
|
544
|
+
|
545
|
+
Terminology
|
546
|
+
-----------
|
547
|
+
|
548
|
+
- `promise` is an object or function with a `then` method whose behavior conforms to this specification.
|
549
|
+
- `thenable` is an object or function that defines a `then` method.
|
550
|
+
- `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
|
551
|
+
- `exception` is a value that is thrown using the throw statement.
|
552
|
+
- `reason` is a value that indicates why a promise was rejected.
|
553
|
+
- `settled` the final resting state of a promise, fulfilled or rejected.
|
554
|
+
|
555
|
+
A promise can be in one of three states: pending, fulfilled, or rejected.
|
556
|
+
|
557
|
+
Promises that are fulfilled have a fulfillment value and are in the fulfilled
|
558
|
+
state. Promises that are rejected have a rejection reason and are in the
|
559
|
+
rejected state. A fulfillment value is never a thenable.
|
560
|
+
|
561
|
+
Promises can also be said to *resolve* a value. If this value is also a
|
562
|
+
promise, then the original promise's settled state will match the value's
|
563
|
+
settled state. So a promise that *resolves* a promise that rejects will
|
564
|
+
itself reject, and a promise that *resolves* a promise that fulfills will
|
565
|
+
itself fulfill.
|
566
|
+
|
567
|
+
|
568
|
+
Basic Usage:
|
569
|
+
------------
|
570
|
+
|
571
|
+
```js
|
572
|
+
var promise = new Promise(function(resolve, reject) {
|
573
|
+
// on success
|
574
|
+
resolve(value);
|
575
|
+
|
576
|
+
// on failure
|
577
|
+
reject(reason);
|
578
|
+
});
|
579
|
+
|
580
|
+
promise.then(function(value) {
|
581
|
+
// on fulfillment
|
582
|
+
}, function(reason) {
|
583
|
+
// on rejection
|
584
|
+
});
|
585
|
+
```
|
586
|
+
|
587
|
+
Advanced Usage:
|
588
|
+
---------------
|
589
|
+
|
590
|
+
Promises shine when abstracting away asynchronous interactions such as
|
591
|
+
`XMLHttpRequest`s.
|
592
|
+
|
593
|
+
```js
|
594
|
+
function getJSON(url) {
|
595
|
+
return new Promise(function(resolve, reject){
|
596
|
+
var xhr = new XMLHttpRequest();
|
597
|
+
|
598
|
+
xhr.open('GET', url);
|
599
|
+
xhr.onreadystatechange = handler;
|
600
|
+
xhr.responseType = 'json';
|
601
|
+
xhr.setRequestHeader('Accept', 'application/json');
|
602
|
+
xhr.send();
|
603
|
+
|
604
|
+
function handler() {
|
605
|
+
if (this.readyState === this.DONE) {
|
606
|
+
if (this.status === 200) {
|
607
|
+
resolve(this.response);
|
608
|
+
} else {
|
609
|
+
reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
|
610
|
+
}
|
611
|
+
}
|
612
|
+
};
|
613
|
+
});
|
614
|
+
}
|
615
|
+
|
616
|
+
getJSON('/posts.json').then(function(json) {
|
617
|
+
// on fulfillment
|
618
|
+
}, function(reason) {
|
619
|
+
// on rejection
|
620
|
+
});
|
621
|
+
```
|
622
|
+
|
623
|
+
Unlike callbacks, promises are great composable primitives.
|
624
|
+
|
625
|
+
```js
|
626
|
+
Promise.all([
|
627
|
+
getJSON('/posts'),
|
628
|
+
getJSON('/comments')
|
629
|
+
]).then(function(values){
|
630
|
+
values[0] // => postsJSON
|
631
|
+
values[1] // => commentsJSON
|
632
|
+
|
633
|
+
return values;
|
634
|
+
});
|
635
|
+
```
|
636
|
+
|
637
|
+
@class Promise
|
638
|
+
@param {function} resolver
|
639
|
+
Useful for tooling.
|
640
|
+
@constructor
|
641
|
+
*/
|
642
|
+
function lib$es6$promise$promise$$Promise(resolver) {
|
643
|
+
this._id = lib$es6$promise$promise$$counter++;
|
644
|
+
this._state = undefined;
|
645
|
+
this._result = undefined;
|
646
|
+
this._subscribers = [];
|
647
|
+
|
648
|
+
if (lib$es6$promise$$internal$$noop !== resolver) {
|
649
|
+
if (!lib$es6$promise$utils$$isFunction(resolver)) {
|
650
|
+
lib$es6$promise$promise$$needsResolver();
|
651
|
+
}
|
652
|
+
|
653
|
+
if (!(this instanceof lib$es6$promise$promise$$Promise)) {
|
654
|
+
lib$es6$promise$promise$$needsNew();
|
655
|
+
}
|
656
|
+
|
657
|
+
lib$es6$promise$$internal$$initializePromise(this, resolver);
|
658
|
+
}
|
659
|
+
}
|
660
|
+
|
661
|
+
lib$es6$promise$promise$$Promise.all = lib$es6$promise$promise$all$$default;
|
662
|
+
lib$es6$promise$promise$$Promise.race = lib$es6$promise$promise$race$$default;
|
663
|
+
lib$es6$promise$promise$$Promise.resolve = lib$es6$promise$promise$resolve$$default;
|
664
|
+
lib$es6$promise$promise$$Promise.reject = lib$es6$promise$promise$reject$$default;
|
665
|
+
|
666
|
+
lib$es6$promise$promise$$Promise.prototype = {
|
667
|
+
constructor: lib$es6$promise$promise$$Promise,
|
668
|
+
|
669
|
+
/**
|
670
|
+
The primary way of interacting with a promise is through its `then` method,
|
671
|
+
which registers callbacks to receive either a promise's eventual value or the
|
672
|
+
reason why the promise cannot be fulfilled.
|
673
|
+
|
674
|
+
```js
|
675
|
+
findUser().then(function(user){
|
676
|
+
// user is available
|
677
|
+
}, function(reason){
|
678
|
+
// user is unavailable, and you are given the reason why
|
679
|
+
});
|
680
|
+
```
|
681
|
+
|
682
|
+
Chaining
|
683
|
+
--------
|
684
|
+
|
685
|
+
The return value of `then` is itself a promise. This second, 'downstream'
|
686
|
+
promise is resolved with the return value of the first promise's fulfillment
|
687
|
+
or rejection handler, or rejected if the handler throws an exception.
|
688
|
+
|
689
|
+
```js
|
690
|
+
findUser().then(function (user) {
|
691
|
+
return user.name;
|
692
|
+
}, function (reason) {
|
693
|
+
return 'default name';
|
694
|
+
}).then(function (userName) {
|
695
|
+
// If `findUser` fulfilled, `userName` will be the user's name, otherwise it
|
696
|
+
// will be `'default name'`
|
697
|
+
});
|
698
|
+
|
699
|
+
findUser().then(function (user) {
|
700
|
+
throw new Error('Found user, but still unhappy');
|
701
|
+
}, function (reason) {
|
702
|
+
throw new Error('`findUser` rejected and we're unhappy');
|
703
|
+
}).then(function (value) {
|
704
|
+
// never reached
|
705
|
+
}, function (reason) {
|
706
|
+
// if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
|
707
|
+
// If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
|
708
|
+
});
|
709
|
+
```
|
710
|
+
If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
|
711
|
+
|
712
|
+
```js
|
713
|
+
findUser().then(function (user) {
|
714
|
+
throw new PedagogicalException('Upstream error');
|
715
|
+
}).then(function (value) {
|
716
|
+
// never reached
|
717
|
+
}).then(function (value) {
|
718
|
+
// never reached
|
719
|
+
}, function (reason) {
|
720
|
+
// The `PedgagocialException` is propagated all the way down to here
|
721
|
+
});
|
722
|
+
```
|
723
|
+
|
724
|
+
Assimilation
|
725
|
+
------------
|
726
|
+
|
727
|
+
Sometimes the value you want to propagate to a downstream promise can only be
|
728
|
+
retrieved asynchronously. This can be achieved by returning a promise in the
|
729
|
+
fulfillment or rejection handler. The downstream promise will then be pending
|
730
|
+
until the returned promise is settled. This is called *assimilation*.
|
731
|
+
|
732
|
+
```js
|
733
|
+
findUser().then(function (user) {
|
734
|
+
return findCommentsByAuthor(user);
|
735
|
+
}).then(function (comments) {
|
736
|
+
// The user's comments are now available
|
737
|
+
});
|
738
|
+
```
|
739
|
+
|
740
|
+
If the assimliated promise rejects, then the downstream promise will also reject.
|
741
|
+
|
742
|
+
```js
|
743
|
+
findUser().then(function (user) {
|
744
|
+
return findCommentsByAuthor(user);
|
745
|
+
}).then(function (comments) {
|
746
|
+
// If `findCommentsByAuthor` fulfills, we'll have the value here
|
747
|
+
}, function (reason) {
|
748
|
+
// If `findCommentsByAuthor` rejects, we'll have the reason here
|
749
|
+
});
|
750
|
+
```
|
751
|
+
|
752
|
+
Simple Example
|
753
|
+
--------------
|
754
|
+
|
755
|
+
Synchronous Example
|
756
|
+
|
757
|
+
```javascript
|
758
|
+
var result;
|
759
|
+
|
760
|
+
try {
|
761
|
+
result = findResult();
|
762
|
+
// success
|
763
|
+
} catch(reason) {
|
764
|
+
// failure
|
765
|
+
}
|
766
|
+
```
|
767
|
+
|
768
|
+
Errback Example
|
769
|
+
|
770
|
+
```js
|
771
|
+
findResult(function(result, err){
|
772
|
+
if (err) {
|
773
|
+
// failure
|
774
|
+
} else {
|
775
|
+
// success
|
776
|
+
}
|
777
|
+
});
|
778
|
+
```
|
779
|
+
|
780
|
+
Promise Example;
|
781
|
+
|
782
|
+
```javascript
|
783
|
+
findResult().then(function(result){
|
784
|
+
// success
|
785
|
+
}, function(reason){
|
786
|
+
// failure
|
787
|
+
});
|
788
|
+
```
|
789
|
+
|
790
|
+
Advanced Example
|
791
|
+
--------------
|
792
|
+
|
793
|
+
Synchronous Example
|
794
|
+
|
795
|
+
```javascript
|
796
|
+
var author, books;
|
797
|
+
|
798
|
+
try {
|
799
|
+
author = findAuthor();
|
800
|
+
books = findBooksByAuthor(author);
|
801
|
+
// success
|
802
|
+
} catch(reason) {
|
803
|
+
// failure
|
804
|
+
}
|
805
|
+
```
|
806
|
+
|
807
|
+
Errback Example
|
808
|
+
|
809
|
+
```js
|
810
|
+
|
811
|
+
function foundBooks(books) {
|
812
|
+
|
813
|
+
}
|
814
|
+
|
815
|
+
function failure(reason) {
|
816
|
+
|
817
|
+
}
|
818
|
+
|
819
|
+
findAuthor(function(author, err){
|
820
|
+
if (err) {
|
821
|
+
failure(err);
|
822
|
+
// failure
|
823
|
+
} else {
|
824
|
+
try {
|
825
|
+
findBoooksByAuthor(author, function(books, err) {
|
826
|
+
if (err) {
|
827
|
+
failure(err);
|
828
|
+
} else {
|
829
|
+
try {
|
830
|
+
foundBooks(books);
|
831
|
+
} catch(reason) {
|
832
|
+
failure(reason);
|
833
|
+
}
|
834
|
+
}
|
835
|
+
});
|
836
|
+
} catch(error) {
|
837
|
+
failure(err);
|
838
|
+
}
|
839
|
+
// success
|
840
|
+
}
|
841
|
+
});
|
842
|
+
```
|
843
|
+
|
844
|
+
Promise Example;
|
845
|
+
|
846
|
+
```javascript
|
847
|
+
findAuthor().
|
848
|
+
then(findBooksByAuthor).
|
849
|
+
then(function(books){
|
850
|
+
// found books
|
851
|
+
}).catch(function(reason){
|
852
|
+
// something went wrong
|
853
|
+
});
|
854
|
+
```
|
855
|
+
|
856
|
+
@method then
|
857
|
+
@param {Function} onFulfilled
|
858
|
+
@param {Function} onRejected
|
859
|
+
Useful for tooling.
|
860
|
+
@return {Promise}
|
861
|
+
*/
|
862
|
+
then: function(onFulfillment, onRejection) {
|
863
|
+
var parent = this;
|
864
|
+
var state = parent._state;
|
865
|
+
|
866
|
+
if (state === lib$es6$promise$$internal$$FULFILLED && !onFulfillment || state === lib$es6$promise$$internal$$REJECTED && !onRejection) {
|
867
|
+
return this;
|
868
|
+
}
|
869
|
+
|
870
|
+
var child = new this.constructor(lib$es6$promise$$internal$$noop);
|
871
|
+
var result = parent._result;
|
872
|
+
|
873
|
+
if (state) {
|
874
|
+
var callback = arguments[state - 1];
|
875
|
+
lib$es6$promise$asap$$default(function(){
|
876
|
+
lib$es6$promise$$internal$$invokeCallback(state, child, callback, result);
|
877
|
+
});
|
878
|
+
} else {
|
879
|
+
lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection);
|
880
|
+
}
|
881
|
+
|
882
|
+
return child;
|
883
|
+
},
|
884
|
+
|
885
|
+
/**
|
886
|
+
`catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
|
887
|
+
as the catch block of a try/catch statement.
|
888
|
+
|
889
|
+
```js
|
890
|
+
function findAuthor(){
|
891
|
+
throw new Error('couldn't find that author');
|
892
|
+
}
|
893
|
+
|
894
|
+
// synchronous
|
895
|
+
try {
|
896
|
+
findAuthor();
|
897
|
+
} catch(reason) {
|
898
|
+
// something went wrong
|
899
|
+
}
|
900
|
+
|
901
|
+
// async with promises
|
902
|
+
findAuthor().catch(function(reason){
|
903
|
+
// something went wrong
|
904
|
+
});
|
905
|
+
```
|
906
|
+
|
907
|
+
@method catch
|
908
|
+
@param {Function} onRejection
|
909
|
+
Useful for tooling.
|
910
|
+
@return {Promise}
|
911
|
+
*/
|
912
|
+
'catch': function(onRejection) {
|
913
|
+
return this.then(null, onRejection);
|
914
|
+
}
|
915
|
+
};
|
916
|
+
function lib$es6$promise$polyfill$$polyfill() {
|
917
|
+
var local;
|
918
|
+
|
919
|
+
if (typeof global !== 'undefined') {
|
920
|
+
local = global;
|
921
|
+
} else if (typeof self !== 'undefined') {
|
922
|
+
local = self;
|
923
|
+
} else {
|
924
|
+
try {
|
925
|
+
local = Function('return this')();
|
926
|
+
} catch (e) {
|
927
|
+
throw new Error('polyfill failed because global object is unavailable in this environment');
|
928
|
+
}
|
929
|
+
}
|
930
|
+
|
931
|
+
var P = local.Promise;
|
932
|
+
|
933
|
+
if (P && Object.prototype.toString.call(P.resolve()) === '[object Promise]' && !P.cast) {
|
934
|
+
return;
|
935
|
+
}
|
936
|
+
|
937
|
+
local.Promise = lib$es6$promise$promise$$default;
|
938
|
+
}
|
939
|
+
var lib$es6$promise$polyfill$$default = lib$es6$promise$polyfill$$polyfill;
|
940
|
+
|
941
|
+
var lib$es6$promise$umd$$ES6Promise = {
|
942
|
+
'Promise': lib$es6$promise$promise$$default,
|
943
|
+
'polyfill': lib$es6$promise$polyfill$$default
|
944
|
+
};
|
945
|
+
|
946
|
+
/* global define:true module:true window: true */
|
947
|
+
if (typeof define === 'function' && define['amd']) {
|
948
|
+
define(function() { return lib$es6$promise$umd$$ES6Promise; });
|
949
|
+
} else if (typeof module !== 'undefined' && module['exports']) {
|
950
|
+
module['exports'] = lib$es6$promise$umd$$ES6Promise;
|
951
|
+
} else if (typeof this !== 'undefined') {
|
952
|
+
this['ES6Promise'] = lib$es6$promise$umd$$ES6Promise;
|
953
|
+
}
|
954
|
+
|
955
|
+
lib$es6$promise$polyfill$$default();
|
956
|
+
}).call(this);
|