question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

allow reverting to native Promise

See original GitHub issue

I was quite surprised that on Chrome I saw that window.Promise was changed from the native one when I use this library as I intentionally didnt call the polyfill method. Then i saw the code:

Object.prototype.toString.call(P.resolve()) === '[object Promise]' && !P.cast)

and realized the issue as in Chrome this test fails (as reported multiple times #139 #136 #132 …)

Normally I wouldnt care this much but Im working on a project in which my code is inserted into other websites and I dont wish to change anything on the global level and unfortunately using this library violates this rule.

Its my opinion that the explanation that the native imp may have issues/bugs is irrelevant for cjs/amd environments. The library shouldnt touch the global object unless explicitly requested., But if you still wish to leave it as it is, please give us the ability to revert back to the original/native Promise. a long the lines of noConflict.

Thanks! Yoav

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:47 (14 by maintainers)

github_iconTop GitHub Comments

4reactions
nazrhyncommented, Jul 12, 2016

As I just had a run-in with this module, I’d like to quote @yoavniran, from above (emphasis mine):

From one of the posts here I think a different version/flavor of this lib without the aggressive override is less preferable as it means that if this library is a dependency of another library you’re using, you wont be able to change the default behavior even if you wanted.

I had already done…

global.Promise = require('bluebird');

…but, when I required the dropbox module, and it required es6-promise, bluebird was overwritten by the polyfill. Luckily, we don’t actually intend to interact with Dropbox at this time; but, if we needed to in the future, how would we prevent this behavior? My only option would be to do something crazy like this:

let p = require('bluebird');
Object.defineProperty(global, 'Promise', {
    get: function () {
        return p;
    },
    set: function () {}
});
2reactions
dlong500commented, Sep 9, 2016

It’s been a while without any activity here. When is the 4.0 release that doesn’t auto-polyfill supposed to come out?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Recovering from rejected promises in JS - Stack Overflow
It seems that JQuery promises do not permit you to change a failure to a success. If, however, you use native promises, you...
Read more >
Introduction to Promises - LearnHowToProgram.com
Once the promise is either fulfilled or rejected, it is complete and becomes immutable. An immutable value can't be changed. A promise is...
Read more >
25. Promises for asynchronous programming - Exploring JS
Let's look at three ways of understanding Promises. The following code contains a Promise-based function asyncFunc() and its invocation. function asyncFunc ...
Read more >
Refetching queries in Apollo Client - Apollo GraphQL Docs
The client.refetchQueries method collects the TResult results returned by onQueryUpdated , defaulting to TResult = Promise<ApolloQueryResult<any>> if ...
Read more >
how to catch "revert" error in truffle test javascript?
@Gagan: You could probably do something like let myContract = null; await tryCatch(async function() {myContract = myContract.new()}, errTypes.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found