vendor: 17,264 bytes, lines 1-673
1(self["webpackChunkLibrary"] = self["webpackChunkLibrary"] || []).push([["common"],{ 2 3/***/ "./node_modules/es6-promise/dist/es6-promise.js" 4/*!******************************************************!*\ 5 !*** ./node_modules/es6-promise/dist/es6-promise.js ***! 6 \******************************************************/ 7(module, __unused_webpack_exports, __webpack_require__) { 8 9/*! 10 * @overview es6-promise - a tiny implementation of Promises/A+. 11 * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald) 12 * @license Licensed under MIT license 13 * See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE 14 * @version v4.2.8+1e68dce6 15 */ 16 17(function (global, factory) { 18 true ? module.exports = factory() : 19 0; 20}(this, (function () { 'use strict'; 21 22function objectOrFunction(x) { 23 var type = typeof x; 24 return x !== null && (type === 'object' || type === 'function'); 25} 26 27function isFunction(x) { 28 return typeof x === 'function'; 29} 30 31 32 33var _isArray = void 0; 34if (Array.isArray) { 35 _isArray = Array.isArray; 36} else { 37 _isArray = function (x) { 38 return Object.prototype.toString.call(x) === '[object Array]'; 39 }; 40} 41 42var isArray = _isArray; 43 44var len = 0; 45var vertxNext = void 0; 46var customSchedulerFn = void 0; 47 48var asap = function asap(callback, arg) { 49 queue[len] = callback; 50 queue[len + 1] = arg; 51 len += 2; 52 if (len === 2) { 53 // If len is 2, that means that we need to schedule an async flush. 54 // If additional callbacks are queued before the queue is flushed, they 55 // will be processed by this flush that we are scheduling. 56 if (customSchedulerFn) { 57 customSchedulerFn(flush); 58 } else { 59 scheduleFlush(); 60 } 61 } 62}; 63 64function setScheduler(scheduleFn) { 65 customSchedulerFn = scheduleFn; 66} 67 68function setAsap(asapFn) { 69 asap = asapFn; 70} 71 72var browserWindow = typeof window !== 'undefined' ? window : undefined; 73var browserGlobal = browserWindow || {}; 74var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; 75var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]'; 76 77// test for web worker but not in IE10 78var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined'; 79 80// node 81function useNextTick() { 82 // node version 0.10.x displays a deprecation warning when nextTick is used recursively 83 // see https://github.com/cujojs/when/issues/410 for details 84 return function () { 85 return process.nextTick(flush); 86 }; 87} 88 89// vertx 90function useVertxTimer() { 91 if (typeof vertxNext !== 'undefined') { 92 return function () { 93 vertxNext(flush); 94 }; 95 } 96 97 return useSetTimeout(); 98} 99 100function useMutationObserver() { 101 var iterations = 0; 102 var observer = new BrowserMutationObserver(flush); 103 var node = document.createTextNode(''); 104 observer.observe(node, { characterData: true }); 105 106 return function () { 107 node.data = iterations = ++iterations % 2; 108 }; 109} 110 111// web worker 112function useMessageChannel() { 113 var channel = new MessageChannel(); 114 channel.port1.onmessage = flush; 115 return function () { 116 return channel.port2.postMessage(0); 117 }; 118} 119 120function useSetTimeout() { 121 // Store setTimeout reference so es6-promise will be unaffected by 122 // other code modifying setTimeout (like sinon.useFakeTimers()) 123 var globalSetTimeout = setTimeout; 124 return function () { 125 return globalSetTimeout(flush, 1); 126 }; 127} 128 129var queue = new Array(1000); 130function flush() { 131 for (var i = 0; i < len; i += 2) { 132 var callback = queue[i]; 133 var arg = queue[i + 1]; 134 135 callback(arg); 136 137 queue[i] = undefined; 138 queue[i + 1] = undefined; 139 } 140 141 len = 0; 142} 143 144function attemptVertx() { 145 try { 146 var vertx = Function('return this')().require('vertx'); 147 vertxNext = vertx.runOnLoop || vertx.runOnContext; 148 return useVertxTimer(); 149 } catch (e) { 150 return useSetTimeout(); 151 } 152} 153 154var scheduleFlush = void 0; 155// Decide what async method to use to triggering processing of queued callbacks: 156if (isNode) { 157 scheduleFlush = useNextTick(); 158} else if (BrowserMutationObserver) { 159 scheduleFlush = useMutationObserver(); 160} else if (isWorker) { 161 scheduleFlush = useMessageChannel(); 162} else if (browserWindow === undefined && "function" === 'function') { 163 scheduleFlush = attemptVertx(); 164} else { 165 scheduleFlush = useSetTimeout(); 166} 167 168function then(onFulfillment, onRejection) { 169 var parent = this; 170 171 var child = new this.constructor(noop); 172 173 if (child[PROMISE_ID] === undefined) { 174 makePromise(child); 175 } 176 177 var _state = parent._state; 178 179 180 if (_state) { 181 var callback = arguments[_state - 1]; 182 asap(function () { 183 return invokeCallback(_state, child, callback, parent._result); 184 }); 185 } else { 186 subscribe(parent, child, onFulfillment, onRejection); 187 } 188 189 return child; 190} 191 192/** 193 `Promise.resolve` returns a promise that will become resolved with the 194 passed `value`. It is shorthand for the following: 195 196 ```javascript 197 let promise = new Promise(function(resolve, reject){ 198 resolve(1); 199 }); 200 201 promise.then(function(value){ 202 // value === 1 203 }); 204 ``` 205 206 Instead of writing the above, your code now simply becomes the following: 207 208 ```javascript 209 let promise = Promise.resolve(1); 210 211 promise.then(function(value){ 212 // value === 1 213 }); 214 ``` 215 216 @method resolve 217 @static 218 @param {Any} value value that the returned promise will be resolved with 219 Useful for tooling. 220 @return {Promise} a promise that will become fulfilled with the given 221 `value` 222*/ 223function resolve$1(object) { 224 /*jshint validthis:true */ 225 var Constructor = this; 226 227 if (object && typeof object === 'object' && object.constructor === Constructor) { 228 return object; 229 } 230 231 var promise = new Constructor(noop); 232 resolve(promise, object); 233 return promise; 234} 235 236var PROMISE_ID = Math.random().toString(36).substring(2); 237 238function noop() {} 239 240var PENDING = void 0; 241var FULFILLED = 1; 242var REJECTED = 2; 243 244function selfFulfillment() { 245 return new TypeError("You cannot resolve a promise with itself"); 246} 247 248function cannotReturnOwn() { 249 return new TypeError('A promises callback cannot return that same promise.'); 250} 251 252function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) { 253 try { 254 then$$1.call(value, fulfillmentHandler, rejectionHandler); 255 } catch (e) { 256 return e; 257 } 258} 259 260function handleForeignThenable(promise, thenable, then$$1) { 261 asap(function (promise) { 262 var sealed = false; 263 var error = tryThen(then$$1, thenable, function (value) { 264 if (sealed) { 265 return; 266 } 267 sealed = true; 268 if (thenable !== value) { 269 resolve(promise, value); 270 } else { 271 fulfill(promise, value); 272 } 273 }, function (reason) { 274 if (sealed) { 275 return; 276 } 277 sealed = true; 278 279 reject(promise, reason); 280 }, 'Settle: ' + (promise._label || ' unknown promise')); 281 282 if (!sealed && error) { 283 sealed = true; 284 reject(promise, error); 285 } 286 }, promise); 287} 288 289function handleOwnThenable(promise, thenable) { 290 if (thenable._state === FULFILLED) { 291 fulfill(promise, thenable._result); 292 } else if (thenable._state === REJECTED) { 293 reject(promise, thenable._result); 294 } else { 295 subscribe(thenable, undefined, function (value) { 296 return resolve(promise, value); 297 }, function (reason) { 298 return reject(promise, reason); 299 }); 300 } 301} 302 303function handleMaybeThenable(promise, maybeThenable, then$$1) { 304 if (maybeThenable.constructor === promise.constructor && then$$1 === then && maybeThenable.constructor.resolve === resolve$1) { 305 handleOwnThenable(promise, maybeThenable); 306 } else { 307 if (then$$1 === undefined) { 308 fulfill(promise, maybeThenable); 309 } else if (isFunction(then$$1)) { 310 handleForeignThenable(promise, maybeThenable, then$$1); 311 } else { 312 fulfill(promise, maybeThenable); 313 } 314 } 315} 316 317function resolve(promise, value) { 318 if (promise === value) { 319 reject(promise, selfFulfillment()); 320 } else if (objectOrFunction(value)) { 321 var then$$1 = void 0; 322 try { 323 then$$1 = value.then; 324 } catch (error) { 325 reject(promise, error); 326 return; 327 } 328 handleMaybeThenable(promise, value, then$$1); 329 } else { 330 fulfill(promise, value); 331 } 332} 333 334function publishRejection(promise) { 335 if (promise._onerror) { 336 promise._onerror(promise._result); 337 } 338 339 publish(promise); 340} 341 342function fulfill(promise, value) { 343 if (promise._state !== PENDING) { 344 return; 345 } 346 347 promise._result = value; 348 promise._state = FULFILLED; 349 350 if (promise._subscribers.length !== 0) { 351 asap(publish, promise); 352 } 353} 354 355function reject(promise, reason) { 356 if (promise._state !== PENDING) { 357 return; 358 } 359 promise._state = REJECTED; 360 promise._result = reason; 361 362 asap(publishRejection, promise); 363} 364 365function subscribe(parent, child, onFulfillment, onRejection) { 366 var _subscribers = parent._subscribers; 367 var length = _subscribers.length; 368 369 370 parent._onerror = null; 371 372 _subscribers[length] = child; 373 _subscribers[length + FULFILLED] = onFulfillment; 374 _subscribers[length + REJECTED] = onRejection; 375 376 if (length === 0 && parent._state) { 377 asap(publish, parent); 378 } 379} 380 381function publish(promise) { 382 var subscribers = promise._subscribers; 383 var settled = promise._state; 384 385 if (subscribers.length === 0) { 386 return; 387 } 388 389 var child = void 0, 390 callback = void 0, 391 detail = promise._result; 392 393 for (var i = 0; i < subscribers.length; i += 3) { 394 child = subscribers[i]; 395 callback = subscribers[i + settled]; 396 397 if (child) { 398 invokeCallback(settled, child, callback, detail); 399 } else { 400 callback(detail); 401 } 402 } 403 404 promise._subscribers.length = 0; 405} 406 407function invokeCallback(settled, promise, callback, detail) { 408 var hasCallback = isFunction(callback), 409 value = void 0, 410 error = void 0, 411 succeeded = true; 412 413 if (hasCallback) { 414 try { 415 value = callback(detail); 416 } catch (e) { 417 succeeded = false; 418 error = e; 419 } 420 421 if (promise === value) { 422 reject(promise, cannotReturnOwn()); 423 return; 424 } 425 } else { 426 value = detail; 427 } 428 429 if (promise._state !== PENDING) { 430 // noop 431 } else if (hasCallback && succeeded) { 432 resolve(promise, value); 433 } else if (succeeded === false) { 434 reject(promise, error); 435 } else if (settled === FULFILLED) { 436 fulfill(promise, value); 437 } else if (settled === REJECTED) { 438 reject(promise, value); 439 } 440} 441 442function initializePromise(promise, resolver) { 443 try { 444 resolver(function resolvePromise(value) { 445 resolve(promise, value); 446 }, function rejectPromise(reason) { 447 reject(promise, reason); 448 }); 449 } catch (e) { 450 reject(promise, e); 451 } 452} 453 454var id = 0; 455function nextId() { 456 return id++; 457} 458 459function makePromise(promise) { 460 promise[PROMISE_ID] = id++; 461 promise._state = undefined; 462 promise._result = undefined; 463 promise._subscribers = []; 464} 465 466function validationError() { 467 return new Error('Array Methods must be provided an Array'); 468} 469 470var Enumerator = function () { 471 function Enumerator(Constructor, input) { 472 this._instanceConstructor = Constructor; 473 this.promise = new Constructor(noop); 474 475 if (!this.promise[PROMISE_ID]) { 476 makePromise(this.promise); 477 } 478 479 if (isArray(input)) { 480 this.length = input.length; 481 this._remaining = input.length; 482 483 this._result = new Array(this.length); 484 485 if (this.length === 0) { 486 fulfill(this.promise, this._result); 487 } else { 488 this.length = this.length || 0; 489 this._enumerate(input); 490 if (this._remaining === 0) { 491 fulfill(this.promise, this._result); 492 } 493 } 494 } else { 495 reject(this.promise, validationError()); 496 } 497 } 498 499 Enumerator.prototype._enumerate = function _enumerate(input) { 500 for (var i = 0; this._state === PENDING && i < input.length; i++) { 501 this._eachEntry(input[i], i); 502 } 503 }; 504 505 Enumerator.prototype._eachEntry = function _eachEntry(entry, i) { 506 var c = this._instanceConstructor; 507 var resolve$$1 = c.resolve; 508 509 510 if (resolve$$1 === resolve$1) { 511 var _then = void 0; 512 var error = void 0; 513 var didError = false; 514 try { 515 _then = entry.then; 516 } catch (e) { 517 didError = true; 518 error = e; 519 } 520 521 if (_then === then && entry._state !== PENDING) { 522 this._settledAt(entry._state, i, entry._result); 523 } else if (typeof _then !== 'function') { 524 this._remaining--; 525 this._result[i] = entry; 526 } else if (c === Promise$1) { 527 var promise = new c(noop); 528 if (didError) { 529 reject(promise, error); 530 } else { 531 handleMaybeThenable(promise, entry, _then); 532 } 533 this._willSettleAt(promise, i); 534 } else { 535 this._willSettleAt(new c(function (resolve$$1) { 536 return resolve$$1(entry); 537 }), i); 538 } 539 } else { 540 this._willSettleAt(resolve$$1(entry), i); 541 } 542 }; 543 544 Enumerator.prototype._settledAt = function _settledAt(state, i, value) { 545 var promise = this.promise; 546 547 548 if (promise._state === PENDING) { 549 this._remaining--; 550 551 if (state === REJECTED) { 552 reject(promise, value); 553 } else { 554 this._result[i] = value; 555 } 556 } 557 558 if (this._remaining === 0) { 559 fulfill(promise, this._result); 560 } 561 }; 562 563 Enumerator.prototype._willSettleAt = function _willSettleAt(promise, i) { 564 var enumerator = this; 565 566 subscribe(promise, undefined, function (value) { 567 return enumerator._settledAt(FULFILLED, i, value); 568 }, function (reason) { 569 return enumerator._settledAt(REJECTED, i, reason); 570 }); 571 }; 572 573 return Enumerator; 574}(); 575 576/** 577 `Promise.all` accepts an array of promises, and returns a new promise which 578 is fulfilled with an array of fulfillment values for the passed promises, or 579 rejected with the reason of the first passed promise to be rejected. It casts all 580 elements of the passed iterable to promises as it runs this algorithm. 581 582 Example: 583 584 ```javascript 585 let promise1 = resolve(1); 586 let promise2 = resolve(2); 587 let promise3 = resolve(3); 588 let promises = [ promise1, promise2, promise3 ]; 589 590 Promise.all(promises).then(function(array){ 591 // The array here would be [ 1, 2, 3 ]; 592 }); 593 ``` 594 595 If any of the `promises` given to `all` are rejected, the first promise 596 that is rejected will be given as an argument to the returned promises's 597 rejection handler. For example: 598 599 Example: 600 601 ```javascript 602 let promise1 = resolve(1); 603 let promise2 = reject(new Error("2")); 604 let promise3 = reject(new Error("3")); 605 let promises = [ promise1, promise2, promise3 ]; 606 607 Promise.all(promises).then(function(array){ 608 // Code here never runs because there are rejected promises! 609 }, function(error) { 610 // error.message === "2" 611 }); 612 ``` 613 614 @method all 615 @static 616 @param {Array} entries array of promises 617 @param {String} label optional string for labeling the promise. 618 Useful for tooling. 619 @return {Promise} promise that is fulfilled when all `promises` have been 620 fulfilled, or rejected if any of them become rejected. 621 @static 622*/ 623function all(entries) { 624 return new Enumerator(this, entries).promise; 625} 626 627/** 628 `Promise.race` returns a new promise which is settled in the same way as the 629 first passed promise to settle. 630 631 Example: 632 633 ```javascript 634 let promise1 = new Promise(function(resolve, reject){ 635 setTimeout(function(){ 636 resolve('promise 1'); 637 }, 200); 638 }); 639 640 let promise2 = new Promise(function(resolve, reject){ 641 setTimeout(function(){ 642 resolve('promise 2'); 643 }, 100); 644 }); 645 646 Promise.race([promise1, promise2]).then(function(result){ 647 // result === 'promise 2' because it was resolved before promise1 648 // was resolved. 649 }); 650 ``` 651 652 `Promise.race` is deterministic in that only the state of the first 653 settled promise matters. For example, even if other promises given to the 654 `promises` array argument are resolved, but the first settled promise has 655 become rejected before the other promises became fulfilled, the returned 656 promise will become rejected: 657 658 ```javascript 659 let promise1 = new Promise(function(resolve, reject){ 660 setTimeout(function(){ 661 resolve('promise 1'); 662 }, 200); 663 }); 664 665 let promise2 = new Promise(function(resolve, reject){ 666 setTimeout(function(){ 667 reject(new Error('promise 2')); 668 }, 100); 669 }); 670 671 Promise.race([promise1, promise2]).then(function(result){ 672 // Code here never runs 673 }, function(reason){
674 // reason.message === 'promise 2' because promise 2 became rejected before 675 // promise 1 became fulfilled 676 }); 677 ``` 678 679 An example real-world use case is implementing timeouts: 680 681 ```javascript 682 Promise.race([ajax('foo.json'), timeout(5000)]) 683 ``` 684 685 @method race 686 @static 687 @param {Array} promises array of promises to observe 688 Useful for tooling. 689 @return {Promise} a promise which settles in the same way as the first passed 690 promise to settle. 691*/ 692function race(entries) { 693 /*jshint validthis:true */ 694 var Constructor = this; 695 696 if (!isArray(entries)) { 697 return new Constructor(function (_, reject) { 698 return reject(new TypeError('You must pass an array to race.')); 699 }); 700 } else { 701 return new Constructor(function (resolve, reject) { 702 var length = entries.length; 703 for (var i = 0; i < length; i++) { 704 Constructor.resolve(entries[i]).then(resolve, reject); 705 } 706 }); 707 } 708} 709 710/** 711 `Promise.reject` returns a promise rejected with the passed `reason`. 712 It is shorthand for the following: 713 714 ```javascript 715 let promise = new Promise(function(resolve, reject){ 716 reject(new Error('WHOOPS')); 717 }); 718 719 promise.then(function(value){ 720 // Code here doesn't run because the promise is rejected! 721 }, function(reason){ 722 // reason.message === 'WHOOPS' 723 }); 724 ``` 725 726 Instead of writing the above, your code now simply becomes the following: 727 728 ```javascript 729 let promise = Promise.reject(new Error('WHOOPS')); 730 731 promise.then(function(value){ 732 // Code here doesn't run because the promise is rejected! 733 }, function(reason){ 734 // reason.message === 'WHOOPS' 735 }); 736 ``` 737 738 @method reject 739 @static 740 @param {Any} reason value that the returned promise will be rejected with. 741 Useful for tooling. 742 @return {Promise} a promise rejected with the given `reason`. 743*/ 744function reject$1(reason) { 745 /*jshint validthis:true */ 746 var Constructor = this; 747 var promise = new Constructor(noop); 748 reject(promise, reason); 749 return promise; 750} 751 752function needsResolver() { 753 throw new TypeError('You must pass a resolver function as the first argument to the promise constructor'); 754} 755 756function needsNew() { 757 throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object c
757onstructor cannot be called as a function."); 758} 759 760/** 761 Promise objects represent the eventual result of an asynchronous operation. The 762 primary way of interacting with a promise is through its `then` method, which 763 registers callbacks to receive either a promise's eventual value or the reason 764 why the promise cannot be fulfilled. 765 766 Terminology 767 ----------- 768 769 - `promise` is an object or function with a `then` method whose behavior conforms to this specification. 770 - `thenable` is an object or function that defines a `then` method. 771 - `value` is any legal JavaScript value (including undefined, a thenable, or a promise). 772 - `exception` is a value that is thrown using the throw statement. 773 - `reason` is a value that indicates why a promise was rejected. 774 - `settled` the final resting state of a promise, fulfilled or rejected. 775 776 A promise can be in one of three states: pending, fulfilled, or rejected. 777 778 Promises that are fulfilled have a fulfillment value and are in the fulfilled 779 state. Promises that are rejected have a rejection reason and are in the 780 rejected state. A fulfillment value is never a thenable. 781 782 Promises can also be said to *resolve* a value. If this value is also a 783 promise, then the original promise's settled state will match the value's 784 settled state. So a promise that *resolves* a promise that rejects will 785 itself reject, and a promise that *resolves* a promise that fulfills will 786 itself fulfill. 787 788 789 Basic Usage: 790 ------------ 791 792 ```js 793 let promise = new Promise(function(resolve, reject) { 794 // on success 795 resolve(value); 796 797 // on failure 798 reject(reason); 799 }); 800 801 promise.then(function(value) { 802 // on fulfillment 803 }, function(reason) { 804 // on rejection 805 }); 806 ``` 807 808 Advanced Usage: 809 --------------- 810 811 Promises shine when abstracting away asynchronous interactions such as 812 `XMLHttpRequest`s. 813 814 ```js 815 function getJSON(url) { 816 return new Promise(function(resolve, reject){ 817 let xhr = new XMLHttpRequest(); 818 819 xhr.open('GET', url); 820 xhr.onreadystatechange = handler; 821 xhr.responseType = 'json'; 822 xhr.setRequestHeader('Accept', 'application/json'); 823 xhr.send(); 824 825 function handler() { 826 if (this.readyState === this.DONE) { 827 if (this.status === 200) { 828 resolve(this.response); 829 } else { 830 reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']')); 831 } 832 } 833 }; 834 }); 835 } 836 837 getJSON('/posts.json').then(function(json) { 838 // on fulfillment 839 }, function(reason) { 840 // on rejection 841 }); 842 ``` 843 844 Unlike callbacks, promises are great composable primitives. 845 846 ```js 847 Promise.all([ 848 getJSON('/posts'), 849 getJSON('/comments') 850 ]).then(function(values){ 851 values[0] // => postsJSON 852 values[1] // => commentsJSON 853 854 return values; 855 }); 856 ``` 857 858 @class Promise 859 @param {Function} resolver 860 Useful for tooling. 861 @constructor 862*/ 863 864var Promise$1 = function () { 865 function Promise(resolver) { 866 this[PROMISE_ID] = nextId(); 867 this._result = this._state = undefined; 868 this._subscribers = []; 869 870 if (noop !== resolver) { 871 typeof resolver !== 'function' && needsResolver(); 872 this instanceof Promise ? initializePromise(this, resolver) : needsNew(); 873 } 874 } 875 876 /** 877 The primary way of interacting with a promise is through its `then` method, 878 which registers callbacks to receive either a promise's eventual value or the 879 reason why the promise cannot be fulfilled. 880 ```js 881 findUser().then(function(user){ 882 // user is available 883 }, function(reason){ 884 // user is unavailable, and you are given the reason why 885 }); 886 ``` 887 Chaining 888 -------- 889 The return value of `then` is itself a promise. This second, 'downstream' 890 promise is resolved with the return value of the first promise's fulfillment 891 or rejection handler, or rejected if the handler throws an exception. 892 ```js 893 findUser().then(function (user) { 894 return user.name; 895 }, function (reason) { 896 return 'default name'; 897 }).then(function (userName) { 898 // If `findUser` fulfilled, `userName` will be the user's name, otherwise it 899 // will be `'default name'` 900 }); 901 findUser().then(function (user) { 902 throw new Error('Found user, but still unhappy'); 903 }, function (reason) { 904 throw new Error('`findUser` rejected and we're unhappy'); 905 }).then(function (value) { 906 // never reached 907 }, function (reason) { 908 // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'. 909 // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'. 910 }); 911 ``` 912 If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream. 913 ```js 914 findUser().then(function (user) { 915 throw new PedagogicalException('Upstream error'); 916 }).then(function (value) { 917 // never reached 918 }).then(function (value) { 919 // never reached 920 }, function (reason) { 921 // The `PedgagocialException` is propagated all the way down to here 922 }); 923 ``` 924 Assimilation 925 ------------ 926 Sometimes the value you want to propagate to a downstream promise can only be 927 retrieved asynchronously. This can be achieved by returning a promise in the 928 fulfillment or rejection handler. The downstream promise will then be pending 929 until the returned promise is settled. This is called *assimilation*. 930 ```js 931 findUser().then(function (user) { 932 return findCommentsByAuthor(user); 933 }).then(function (comments) { 934 // The user's comments are now available 935 }); 936 ``` 937 If the assimliated promise rejects, then the downstream promise will also reject. 938 ```js 939 findUser().then(function (user) { 940 return findCommentsByAuthor(user); 941 }).then(function (comments) { 942 // If `findCommentsByAuthor` fulfills, we'll have the value here 943 }, function (reason) { 944 // If `findCommentsByAuthor` rejects, we'll have the reason here 945 }); 946 ```
vendor: 4,903 bytes, lines 947-1187
947 Simple Example 948 -------------- 949 Synchronous Example 950 ```javascript 951 let result; 952 try { 953 result = findResult(); 954 // success 955 } catch(reason) { 956 // failure 957 } 958 ``` 959 Errback Example 960 ```js 961 findResult(function(result, err){ 962 if (err) { 963 // failure 964 } else { 965 // success 966 } 967 }); 968 ``` 969 Promise Example; 970 ```javascript 971 findResult().then(function(result){ 972 // success 973 }, function(reason){ 974 // failure 975 }); 976 ``` 977 Advanced Example 978 -------------- 979 Synchronous Example 980 ```javascript 981 let author, books; 982 try { 983 author = findAuthor(); 984 books = findBooksByAuthor(author); 985 // success 986 } catch(reason) { 987 // failure 988 } 989 ``` 990 Errback Example 991 ```js 992 function foundBooks(books) { 993 } 994 function failure(reason) { 995 } 996 findAuthor(function(author, err){ 997 if (err) { 998 failure(err); 999 // failure 1000 } else { 1001 try { 1002 findBoooksByAuthor(author, function(books, err) { 1003 if (err) { 1004 failure(err); 1005 } else { 1006 try { 1007 foundBooks(books); 1008 } catch(reason) { 1009 failure(reason); 1010 } 1011 } 1012 }); 1013 } catch(error) { 1014 failure(err); 1015 } 1016 // success 1017 } 1018 }); 1019 ``` 1020 Promise Example; 1021 ```javascript 1022 findAuthor(). 1023 then(findBooksByAuthor). 1024 then(function(books){ 1025 // found books 1026 }).catch(function(reason){ 1027 // something went wrong 1028 }); 1029 ``` 1030 @method then 1031 @param {Function} onFulfilled 1032 @param {Function} onRejected 1033 Useful for tooling. 1034 @return {Promise} 1035 */ 1036 1037 /** 1038 `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same 1039 as the catch block of a try/catch statement. 1040 ```js 1041 function findAuthor(){ 1042 throw new Error('couldn't find that author'); 1043 } 1044 // synchronous 1045 try { 1046 findAuthor(); 1047 } catch(reason) { 1048 // something went wrong 1049 } 1050 // async with promises 1051 findAuthor().catch(function(reason){ 1052 // something went wrong 1053 }); 1054 ``` 1055 @method catch 1056 @param {Function} onRejection 1057 Useful for tooling. 1058 @return {Promise} 1059 */ 1060 1061 1062 Promise.prototype.catch = function _catch(onRejection) { 1063 return this.then(null, onRejection); 1064 }; 1065 1066 /** 1067 `finally` will be invoked regardless of the promise's fate just as native 1068 try/catch/finally behaves 1069 1070 Synchronous example: 1071 1072 ```js 1073 findAuthor() { 1074 if (Math.random() > 0.5) { 1075 throw new Error(); 1076 } 1077 return new Author(); 1078 } 1079 1080 try { 1081 return findAuthor(); // succeed or fail 1082 } catch(error) { 1083 return findOtherAuther(); 1084 } finally { 1085 // always runs 1086 // doesn't affect the return value 1087 } 1088 ``` 1089 1090 Asynchronous example: 1091 1092 ```js 1093 findAuthor().catch(function(reason){ 1094 return findOtherAuther(); 1095 }).finally(function(){ 1096 // author was either found, or not 1097 }); 1098 ``` 1099 1100 @method finally 1101 @param {Function} callback 1102 @return {Promise} 1103 */ 1104 1105 1106 Promise.prototype.finally = function _finally(callback) { 1107 var promise = this; 1108 var constructor = promise.constructor; 1109 1110 if (isFunction(callback)) { 1111 return promise.then(function (value) { 1112 return constructor.resolve(callback()).then(function () { 1113 return value; 1114 }); 1115 }, function (reason) { 1116 return constructor.resolve(callback()).then(function () { 1117 throw reason; 1118 }); 1119 }); 1120 } 1121 1122 return promise.then(callback, callback); 1123 }; 1124 1125 return Promise; 1126}(); 1127 1128Promise$1.prototype.then = then; 1129Promise$1.all = all; 1130Promise$1.race = race; 1131Promise$1.resolve = resolve$1; 1132Promise$1.reject = reject$1; 1133Promise$1._setScheduler = setScheduler; 1134Promise$1._setAsap = setAsap; 1135Promise$1._asap = asap; 1136 1137/*global self*/ 1138function polyfill() { 1139 var local = void 0; 1140 1141 if (typeof __webpack_require__.g !== 'undefined') { 1142 local = __webpack_require__.g; 1143 } else if (typeof self !== 'undefined') { 1144 local = self; 1145 } else { 1146 try { 1147 local = Function('return this')(); 1148 } catch (e) { 1149 throw new Error('polyfill failed because global object is unavailable in this environment'); 1150 } 1151 } 1152 1153 var P = local.Promise; 1154 1155 if (P) { 1156 var promiseToString = null; 1157 try { 1158 promiseToString = Object.prototype.toString.call(P.resolve()); 1159 } catch (e) { 1160 // silently ignored 1161 } 1162 1163 if (promiseToString === '[object Promise]' && !P.cast) { 1164 return; 1165 } 1166 } 1167 1168 local.Promise = Promise$1; 1169} 1170 1171// Strange compat.. 1172Promise$1.polyfill = polyfill; 1173Promise$1.Promise = Promise$1; 1174 1175return Promise$1; 1176 1177}))); 1178 1179 1180 1181//# sourceMappingURL=es6-promise.map 1182 1183 1184/***/ } 1185 1186}]); 1187//# sourceMappingURL=common.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.