Skip to content

Commit

Permalink
Use existing root.pubSub when present (#213)
Browse files Browse the repository at this point in the history
This means that loading `pubsub-js` more than once in the same environment will work as the author expects. A warning will be output on the console to make the developer aware of the duplication.
  • Loading branch information
abishek-srinivasan authored Nov 11, 2021
1 parent e588bc3 commit ae3284d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
'use strict';

var PubSub = {};
root.PubSub = PubSub;
factory(PubSub);

if (root.PubSub) {
PubSub = root.PubSub;
console.warn("PubSub already loaded, using existing version");
} else {
root.PubSub = PubSub;
factory(PubSub);
}
// CommonJS and Node.js module support
if (typeof exports === 'object'){
if (module !== undefined && module.exports) {
Expand Down

0 comments on commit ae3284d

Please # to comment.