eclipse-paho / eclipse-paho/paho.mqtt.javascript
Add support for CommonJS and AMD
- Dominant language
- JavaScript
- Stars
- 1.2k
- Forks
- 466
- PR merge metrics
- No merged PRs in 30d
Description
migrated from Bugzilla [#437204](https://bugs.eclipse.org/bugs/show_bug.cgi?id=437204)
status UNCONFIRMED severity _normal_ in component _MQTT-JS_ for _0.9_
Reported in version _future_ on platform _PC_
Assigned to: James Sutton
On 2014-06-11 12:13:50 -0400, Tim-Daniel Jacobi wrote:
> Rationale for this request is to be able to load the JavaScript client asynchronously as a dependency as it is often required by larger scaled JavaScript projects. This addition would also ease the use of the client in Dojo based projects.
>
> There are three major patterns of using/loading a JavaScript module nowadays.
>
> Attach your module to the global namespace (global in node, window in the browser), this is the current approach:
> // define it
> MyModule = { // module code };
> // use it
> MyModule.myMethod();
>
> Define it as a CommonJS module (like all npm modules do):
> // define it (mymodule.js)
> module.exports = { // module code };
> // use it (app.js)
> var mymodule = require('./mymodule');
> mymodule.myMethod();
>
> Define it as AMD module (for AngularJS, Dojo, ...)
> //define it
> define(function(){ // module code });
> // use it
> require(['mymodule'], function(mymodule){
> mymodule.myMethod();
> });
>
> The JavaScript MQTT client only supports the first pattern at the moment. Having it support all three patterns is as easy as wrapping the current code with the following. This will also ensure backwards compatibility.
>
> (function(name, definition) {
> if (typeof module != 'undefined') module.exports = definition();
> else if (typeof define == 'function' && typeof define.amd == 'object') define(definition);
> else this[name] = definition();
> }('Messaging', function() {
> // Current code (mqttws31.js lines 84-2011) goes here
> }));
>
> Further reading:
> AMD: http://dojotoolkit.org/documentation/tutorials/1.9/modules/
> CommonJS: http://dailyjs.com/2010/10/18/modules/
On 2015-08-14 06:36:03 -0400, Ian Craggs wrote:
> Assigning to James
Contributor guide
Assessment
This issue has not been assessed yet.