eclipse / paho.mqtt.javascript

paho.mqtt.javascript
Other
1.14k stars 468 forks source link

Support browser usage in strict mode #190

Closed mpcowan closed 5 years ago

mpcowan commented 5 years ago

Currently, when passing this inside the scope setup function in a browser leads to a Cannot set property Paho of undefined error.

To address this we wrap up the initialization logic in another scoped IIFE that sets up a commonjsGlobal variable with appropriate fallback.

We can then use this variable instead of the undefined this when we attempt to export the Paho library.

Signed-off-by: Matt Cowan mcowan@atlassian.com

mpcowan commented 5 years ago

It is easiest to view the diff with whitespace changes hidden, since a lot of indenting happened: https://github.com/eclipse/paho.mqtt.javascript/pull/190/files?utf8=%E2%9C%93&diff=unified&w=1

I'm struggling to understand the test failures, so I can certainly use a hand there.

icraggs commented 5 years ago

The build failure was general, due to package dependencies needing updating. I've merged these changes into the develop branch, and the build & tests worked:

https://travis-ci.org/eclipse/paho.mqtt.javascript/builds/541371747

The auto-merging didn't work, but I think I got the manual resolution correct. Let me know if there's any issue. Thanks!