Search code examples
javascriptpromisespotify

How to use setPromiseImplementation method from SpotifyWebAPI


I want to use library SpotifyWebApi (link) with browser javascript (chrome extension).

If you want to use a Promises/A+ library, you can set it

spotifyApi.setPromiseImplementation(Q);

If I did this, raised error

Uncaught ReferenceError: Q is not defined

If like this

spotifyApi.setPromiseImplementation(Promise);

Error handling response: TypeError: _promiseImplementation.defer is not a function

How to use Promise with this library?


Solution

  • How to use Promise with this library?

    If you mean the native global Promise, then just do nothing - it works out of the box. You only need setPromiseImplementation if you want to use a custom promise library.

    How to use setPromiseImplementation method?

    I'd argue that the functionality of that is broken. It only works with Q.js or a Q-compatible API, namely the library function that you pass would need to support both the promise constructor pattern and the deferred pattern. If you plan to use an ES6-Promise drop-in libary and don't want to replace the native global window.Promise, I'd suggest to file a bug report.