From 0cd01046803cf3a7c5cc73275bef96359e9e1998 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Sat, 26 Jul 2014 09:02:19 +0200 Subject: [PATCH 1/2] Fix CommonJS issues for contexts without `module` global This pull request fixes issues for CommonJS contexts that doesn't provide the `module` global by implementing a slightly tweaked version of https://github.com/umdjs/umd/blob/master/commonjsStrictGlobal.js The adjustments made are just to pass in the expected `root` to still allow the jQuery version to work. --- src/pubsub.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/pubsub.js b/src/pubsub.js index 7b48384..8d17bea 100755 --- a/src/pubsub.js +++ b/src/pubsub.js @@ -13,26 +13,28 @@ https://github.com/mroderick/PubSubJS require, window */ -(function(root, factory){ +(function (root, factory){ 'use strict'; - // CommonJS - if (typeof exports === 'object' && module){ - module.exports = factory(); + if (typeof define === 'function' && define.amd){ + // AMD. Register as an anonymous module. + define(['exports'], function (exports, b){ + factory((root.PubSub = exports), b); + }); - // AMD - } else if (typeof define === 'function' && define.amd){ - define(factory); - // Browser - } else { - root.PubSub = factory(); - } -}( ( typeof window === 'object' && window ) || this, function(){ + } else if (typeof exports === 'object'){ + // CommonJS + factory(exports); + + } else { + // Browser globals + factory((root.PubSub = {})); + } +}(( typeof window === 'object' && window ) || this, function (PubSub){ 'use strict'; - var PubSub = {}, - messages = {}, + var messages = {}, lastUid = -1; function hasKeys(obj){ @@ -210,6 +212,4 @@ https://github.com/mroderick/PubSubJS return result; }; - - return PubSub; })); From 4e5a118934ece1359e35c3a4a977402f529604cf Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Sat, 9 Aug 2014 14:10:54 +0200 Subject: [PATCH 2/2] Stop leaking global Use the [commonjsStrict](https://github.com/umdjs/umd/blob/master/commonjsStrict.js) pattern instead of [commonjsStrictGlobal](https://github.com/umdjs/umd/blob/master/commonjsStrictGlobal.js), so we don't introduce a new global. --- src/pubsub.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pubsub.js b/src/pubsub.js index 8d17bea..daa2ff8 100755 --- a/src/pubsub.js +++ b/src/pubsub.js @@ -18,9 +18,7 @@ https://github.com/mroderick/PubSubJS if (typeof define === 'function' && define.amd){ // AMD. Register as an anonymous module. - define(['exports'], function (exports, b){ - factory((root.PubSub = exports), b); - }); + define(['exports'], factory); } else if (typeof exports === 'object'){ // CommonJS