1 | /**
|
2 | @license
|
3 | Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
|
4 | This code may only be used under the BSD style license found at
|
5 | http://polymer.github.io/LICENSE.txt The complete set of authors may be found at
|
6 | http://polymer.github.io/AUTHORS.txt The complete set of contributors may be
|
7 | found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as
|
8 | part of the polymer project is also subject to an additional IP rights grant
|
9 | found at http://polymer.github.io/PATENTS.txt
|
10 | */
|
11 | import PromisePolyfill from 'promise-polyfill/src/index.js';
|
12 | /*
|
13 | Assign the ES6 promise polyfill to window ourselves instead of using the "auto"
|
14 | polyfill to work around
|
15 | https://github.com/webcomponents/webcomponentsjs/issues/837
|
16 | */
|
17 | if (!window.Promise) {
|
18 | window.Promise = PromisePolyfill;
|
19 | // save Promise API
|
20 | /* eslint-disable no-self-assign */
|
21 | // PromisePolyfill.prototype['catch'] = PromisePolyfill.prototype.catch;
|
22 | PromisePolyfill.prototype['then'] = PromisePolyfill.prototype.then;
|
23 | // PromisePolyfill.prototype['finally'] = PromisePolyfill.prototype.finally;
|
24 | PromisePolyfill['all'] = PromisePolyfill.all;
|
25 | PromisePolyfill['race'] = PromisePolyfill.race;
|
26 | PromisePolyfill['resolve'] = PromisePolyfill.resolve;
|
27 | PromisePolyfill['reject'] = PromisePolyfill.reject;
|
28 | /* eslint-enable */
|
29 | // approach copied from
|
30 | // https://github.com/Polymer/polymer/blob/v3.0.2/lib/utils/async.js
|
31 | const node = document.createTextNode('');
|
32 | const twiddleNode = function twiddleNode() {
|
33 | node.textContent = node.textContent.length > 0 ? '' : 'a';
|
34 | };
|
35 | /** @type {!Array<function():void>} */
|
36 | const callbacks = [];
|
37 | (new MutationObserver(() => {
|
38 | const len = callbacks.length;
|
39 | for (let i = 0; i < len; i++) {
|
40 | callbacks[i]();
|
41 | }
|
42 | callbacks.splice(0, len);
|
43 | }).observe(node, { characterData: true }));
|
44 | // set _immediateFn to a MutationObserver for close-to-native timing
|
45 | PromisePolyfill._immediateFn = (fn) => {
|
46 | callbacks.push(fn);
|
47 | twiddleNode();
|
48 | };
|
49 | }
|
50 | //# sourceMappingURL=promise.js.map |
\ | No newline at end of file |