Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont change global promise props #1294

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions src/helpers/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,16 +653,8 @@ export function newScope (fn, props, a1, a2) {
psd.global = false;
psd.id = ++zone_id_counter;
// Prepare for promise patching (done in usePSD):
var globalEnv = globalPSD.env;
psd.env = patchGlobalPromise ? {
Promise: DexiePromise, // Changing window.Promise could be omitted for Chrome and Edge, where IDB+Promise plays well!
PromiseProp: {value: DexiePromise, configurable: true, writable: true},
all: DexiePromise.all,
race: DexiePromise.race,
allSettled: DexiePromise.allSettled,
any: DexiePromise.any,
resolve: DexiePromise.resolve,
reject: DexiePromise.reject,
} : {};
if (props) extend(psd, props);

Expand Down Expand Up @@ -752,8 +744,6 @@ function switchToZone (targetZone, bEnteringZone) {
if (currentZone === globalPSD) globalPSD.env = snapShot();

if (patchGlobalPromise) {
// Let's patch the global and native Promises (may be same or may be different)
var GlobalPromise = globalPSD.env.Promise;
// Swich environments (may be PSD-zone or the global zone. Both apply.)
var targetEnv = targetZone.env;

Expand All @@ -762,30 +752,13 @@ function switchToZone (targetZone, bEnteringZone) {

// Set this Promise to window.Promise so that transiled async functions will work on Firefox, Safari and IE, as well as with Zonejs and angular.
Object.defineProperty(_global, 'Promise', targetEnv.PromiseProp);

// Support Promise.all() etc to work indexedDB-safe also when people are including es6-promise as a module (they might
// not be accessing global.Promise but a local reference to it)
GlobalPromise.all = targetEnv.all;
GlobalPromise.race = targetEnv.race;
GlobalPromise.resolve = targetEnv.resolve;
GlobalPromise.reject = targetEnv.reject;
if (targetEnv.allSettled) GlobalPromise.allSettled = targetEnv.allSettled;
if (targetEnv.any) GlobalPromise.any = targetEnv.any;
}
}
}

function snapShot () {
var GlobalPromise = _global.Promise;
return patchGlobalPromise ? {
Promise: GlobalPromise,
PromiseProp: Object.getOwnPropertyDescriptor(_global, "Promise"),
all: GlobalPromise.all,
race: GlobalPromise.race,
allSettled: GlobalPromise.allSettled,
any: GlobalPromise.any,
resolve: GlobalPromise.resolve,
reject: GlobalPromise.reject,
} : {};
}

Expand Down
Loading