kriskowal / asap

High-priority task queue for Node.js and browsers
MIT License
608 stars 46 forks source link

Fix browserify and webpack bundling problems. #67

Closed visortelle closed 8 years ago

visortelle commented 8 years ago

I had a problem with using this library as a dependency of other packages. This fix solve the problem and all tests are passed succesfully.

kriskowal commented 8 years ago

You will need to use the ternary operator with typeof for these not to be reference errors in the environments in which they are not defined. It can be done with just global and self. On Sun, Sep 25, 2016 at 10:00 AM Kirill Volkovich notifications@github.com wrote:

@visortelle commented on this pull request.

In browser-raw.js https://github.com/kriskowal/asap/pull/67:

@@ -76,9 +76,9 @@ function flush() {

// Safari 6 and 6.1 for desktop, iPad, and iPhone are the only browsers that // have WebKitMutationObserver but not un-prefixed MutationObserver. -// Must use global instead of window to work in both frames and web -// workers. global is a provision of Browserify, Mr, Mrs, or Mop. -var BrowserMutationObserver = global.MutationObserver || global.WebKitMutationObserver; +var BrowserMutationObserver = global ?

What's about:

var global = window || self || global; var BrowserMutationObserver = global.MutationObserver || global.WebKitMutationObserver;

??

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/kriskowal/asap/pull/67, or mute the thread https://github.com/notifications/unsubscribe-auth/AADrhmOTzxgDdANBJWvOeTAz-tmhGvy5ks5qtqiggaJpZM4KFIt1 .

visortelle commented 8 years ago

Do you mean something like this?

var BrowserMutationObserver = typeof global === 'object' ?
    (global.MutationObserver || global.WebKitMutationObserver) :
    (self.MutationObserver || self.WebKitMutationObserver);
kriskowal commented 8 years ago

Yes, or

var scope = typeof global !== 'undefined' ? global : self;
var BrowserMutationObserver = scope.MutationObserver || scope.WebKitMutationObserver;

Note also that vars are hoisted so using the same variable on the left and right hand side would have odd behavior:

var global = typeof global !== 'undefined' ? global : self;

In this case, it will always evaluate self because global exists in scope and typeof global is 'undefined'.

visortelle commented 8 years ago

Continue here https://github.com/kriskowal/asap/pull/68