forked from mystiq/hydrogen-web
change method name
This commit is contained in:
parent
9498524369
commit
706ec97296
2 changed files with 15 additions and 14 deletions
|
@ -16,8 +16,6 @@ limitations under the License.
|
||||||
|
|
||||||
// polyfills needed for IE11
|
// polyfills needed for IE11
|
||||||
|
|
||||||
const hasNativePromise = typeof window.Promise === "function";
|
|
||||||
|
|
||||||
// TODO: don't include a polyfill for promises as we already provide one
|
// TODO: don't include a polyfill for promises as we already provide one
|
||||||
import "core-js/stable";
|
import "core-js/stable";
|
||||||
import "regenerator-runtime/runtime";
|
import "regenerator-runtime/runtime";
|
||||||
|
@ -28,12 +26,15 @@ import "mdn-polyfills/Element.prototype.closest";
|
||||||
// it will also include the file supporting *all* the encodings,
|
// it will also include the file supporting *all* the encodings,
|
||||||
// weighing a good extra 500kb :-(
|
// weighing a good extra 500kb :-(
|
||||||
import "text-encoding";
|
import "text-encoding";
|
||||||
import {Promifill} from "./utils/Promifill.js";
|
import Promise from "../lib/es6-promise/lib/es6-promise/promise.js";
|
||||||
|
|
||||||
// console.log("hasNativePromise", hasNativePromise);
|
const flush = Promise._flush;
|
||||||
// if (!hasNativePromise) {
|
Promise._flush = function() {
|
||||||
window.Promise = Promifill;
|
console.log("manually flushing promise queue");
|
||||||
// }
|
flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.Promise = Promise;
|
||||||
|
|
||||||
// TODO: contribute this to mdn-polyfills
|
// TODO: contribute this to mdn-polyfills
|
||||||
if (!Element.prototype.remove) {
|
if (!Element.prototype.remove) {
|
||||||
|
|
|
@ -52,11 +52,11 @@ export function reqAsPromise(req) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
req.addEventListener("success", event => {
|
req.addEventListener("success", event => {
|
||||||
resolve(event.target.result);
|
resolve(event.target.result);
|
||||||
Promise.flushQueue && Promise.flushQueue();
|
Promise._flush && Promise._flush();
|
||||||
});
|
});
|
||||||
req.addEventListener("error", () => {
|
req.addEventListener("error", () => {
|
||||||
reject(new IDBRequestError(req));
|
reject(new IDBRequestError(req));
|
||||||
Promise.flushQueue && Promise.flushQueue();
|
Promise._flush && Promise._flush();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -65,11 +65,11 @@ export function txnAsPromise(txn) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
txn.addEventListener("complete", () => {
|
txn.addEventListener("complete", () => {
|
||||||
resolve();
|
resolve();
|
||||||
Promise.flushQueue && Promise.flushQueue();
|
Promise._flush && Promise._flush();
|
||||||
});
|
});
|
||||||
txn.addEventListener("abort", () => {
|
txn.addEventListener("abort", () => {
|
||||||
reject(new IDBRequestError(txn));
|
reject(new IDBRequestError(txn));
|
||||||
Promise.flushQueue && Promise.flushQueue();
|
Promise._flush && Promise._flush();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -79,14 +79,14 @@ export function iterateCursor(cursorRequest, processValue) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
cursorRequest.onerror = () => {
|
cursorRequest.onerror = () => {
|
||||||
reject(new IDBRequestError(cursorRequest));
|
reject(new IDBRequestError(cursorRequest));
|
||||||
Promise.flushQueue && Promise.flushQueue();
|
Promise._flush && Promise._flush();
|
||||||
};
|
};
|
||||||
// collect results
|
// collect results
|
||||||
cursorRequest.onsuccess = (event) => {
|
cursorRequest.onsuccess = (event) => {
|
||||||
const cursor = event.target.result;
|
const cursor = event.target.result;
|
||||||
if (!cursor) {
|
if (!cursor) {
|
||||||
resolve(false);
|
resolve(false);
|
||||||
Promise.flushQueue && Promise.flushQueue();
|
Promise._flush && Promise._flush();
|
||||||
return; // end of results
|
return; // end of results
|
||||||
}
|
}
|
||||||
const result = processValue(cursor.value, cursor.key);
|
const result = processValue(cursor.value, cursor.key);
|
||||||
|
@ -95,7 +95,7 @@ export function iterateCursor(cursorRequest, processValue) {
|
||||||
|
|
||||||
if (done) {
|
if (done) {
|
||||||
resolve(true);
|
resolve(true);
|
||||||
Promise.flushQueue && Promise.flushQueue();
|
Promise._flush && Promise._flush();
|
||||||
} else if(jumpTo) {
|
} else if(jumpTo) {
|
||||||
cursor.continue(jumpTo);
|
cursor.continue(jumpTo);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue