Skip to content

Commit

Permalink
closes #2
Browse files Browse the repository at this point in the history
Fixed global pollution when working with AMD
  • Loading branch information
miki2826 committed Jul 2, 2015
1 parent 27779e5 commit e644791
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 217 deletions.
18 changes: 7 additions & 11 deletions src/Channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,9 @@
/* istanbul ignore if */
//<amd>
if ("function" === typeof define && define.amd) {
// Browser globals
root.Chronos = root.Chronos || {};

// AMD. Register as an anonymous module.
define("Chronos.Channels", ["exports", "Chronos.Events", "Chronos.Commands", "Chronos.Reqres"], function () {
if (!root.Chronos.Channels) {
factory(root, root.Chronos, root.Chronos.Events, root.Chronos.Commands, root.Chronos.ReqRes);
}

return root.Chronos.Channels;
define("Chronos.Channels", ["Chronos.Events", "Chronos.Commands", "Chronos.Reqres"], function (Events, Commands, Reqres) {
return factory(root, root, Events, Commands, Reqres, true);
});
return;
}
Expand All @@ -36,7 +29,7 @@
root.Chronos = root.Chronos || {};
factory(root, root.Chronos, root.Chronos.Events, root.Chronos.Commands, root.Chronos.ReqRes);
}
}(typeof ChronosRoot === "undefined" ? this : ChronosRoot, function (root, exports, Events, Commands, ReqRes) {
}(typeof ChronosRoot === "undefined" ? this : ChronosRoot, function (root, exports, Events, Commands, ReqRes, hide) {
function Channels(options) {

options = options || {};
Expand Down Expand Up @@ -67,5 +60,8 @@

// attach properties to the exports object to define
// the exported module properties.
exports.Channels = exports.Channels || Channels;
if (!hide) {
exports.Channels = exports.Channels || Channels;
}
return Channels;
}));
18 changes: 7 additions & 11 deletions src/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@
/* istanbul ignore if */
//<amd>
if ("function" === typeof define && define.amd) {
// Browser globals
root.Chronos = root.Chronos || {};

// AMD. Register as an anonymous module.
define("Chronos.Commands", ["exports", "Chronos.EventsUtil", "Chronos.CommandsUtil"], function () {
if (!root.Chronos.Commands) {
factory(root, root.Chronos, root.Chronos.EventsUtil, root.Chronos.CommandsUtil);
}

return root.Chronos.Commands;
define("Chronos.Commands", ["Chronos.EventsUtil", "Chronos.CommandsUtil"], function (EventsUtil, CommandsUtil) {
return factory(root, root, EventsUtil, CommandsUtil, true);
});
return;
}
Expand All @@ -33,7 +26,7 @@
root.Chronos = root.Chronos || {};
factory(root, root.Chronos, root.Chronos.EventsUtil, root.Chronos.CommandsUtil);
}
}(typeof ChronosRoot === "undefined" ? this : ChronosRoot, function (root, exports, evUtil, cmdUtil) {
}(typeof ChronosRoot === "undefined" ? this : ChronosRoot, function (root, exports, evUtil, cmdUtil, hide) {
"use strict";

function Commands(defaults) {
Expand Down Expand Up @@ -178,5 +171,8 @@

// attach properties to the exports object to define
// the exported module properties.
exports.Commands = exports.Commands || Commands;
if (!hide) {
exports.Commands = exports.Commands || Commands;
}
return Commands;
}));
18 changes: 7 additions & 11 deletions src/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@
/* istanbul ignore if */
//<amd>
if ("function" === typeof define && define.amd) {
// Browser globals
root.Chronos = root.Chronos || {};

// AMD. Register as an anonymous module.
define("Chronos.Events", ["exports", "Chronos.EventsUtil"], function () {
if (!root.Chronos.Events) {
factory(root, root.Chronos, root.Chronos.EventsUtil);
}

return root.Chronos.Events;
define("Chronos.Events", ["Chronos.EventsUtil"], function (EventsUtil) {
return factory(root, root, EventsUtil, true);
});
return;
}
Expand All @@ -32,7 +25,7 @@
root.Chronos = root.Chronos || {};
factory(root, root.Chronos, root.Chronos.EventsUtil);
}
}(typeof ChronosRoot === "undefined" ? this : ChronosRoot, function (root, exports, evUtil) {
}(typeof ChronosRoot === "undefined" ? this : ChronosRoot, function (root, exports, evUtil, hide) {
"use strict";

function Events(defaults) {
Expand Down Expand Up @@ -244,5 +237,8 @@

// attach properties to the exports object to define
// the exported module properties.
exports.Events = exports.Events || Events;
if (!hide) {
exports.Events = exports.Events || Events;
}
return Events;
}));
18 changes: 7 additions & 11 deletions src/Reqres.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@
/* istanbul ignore if */
//<amd>
if ("function" === typeof define && define.amd) {
// Browser globals
root.Chronos = root.Chronos || {};

// AMD. Register as an anonymous module.
define("Chronos.Reqres", ["exports", "Chronos.EventsUtil", "Chronos.CommandsUtil"], function () {
if (!root.Chronos.ReqRes) {
factory(root, root.Chronos, root.Chronos.EventsUtil, root.Chronos.CommandsUtil);
}

return root.Chronos.ReqRes;
define("Chronos.Reqres", ["Chronos.EventsUtil", "Chronos.CommandsUtil"], function (EventsUtil, CommandsUtil) {
return factory(root, root, EventsUtil, CommandsUtil, true);
});
return;
}
Expand All @@ -33,7 +26,7 @@
root.Chronos = root.Chronos || {};
factory(root, root.Chronos, root.Chronos.EventsUtil, root.Chronos.CommandsUtil);
}
}(typeof ChronosRoot === "undefined" ? this : ChronosRoot, function (root, exports, evUtil, cmdUtil) {
}(typeof ChronosRoot === "undefined" ? this : ChronosRoot, function (root, exports, evUtil, cmdUtil, hide) {
function ReqRes(defaults) {
var appName = "ReqRes",
attrName = "reqName",
Expand Down Expand Up @@ -178,5 +171,8 @@

// attach properties to the exports object to define
// the exported module properties.
exports.ReqRes = exports.ReqRes || ReqRes;
if (!hide) {
exports.ReqRes = exports.ReqRes || ReqRes;
}
return ReqRes;
}));
18 changes: 8 additions & 10 deletions src/courier/PostMessageChannel.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
;(function (root, chronosRoot, factory) {
"use strict";

chronosRoot.Chronos = chronosRoot.Chronos || {};

/* istanbul ignore if */
//<amd>
if ("function" === typeof define && define.amd) {

// AMD. Register as an anonymous module.
define("Chronos.PostMessageChannel", ["exports", "Chronos.PostMessageUtilities", "Chronos.PostMessageChannelPolyfill"], function () {
if (!chronosRoot.Chronos.PostMessageChannel) {
factory(root, chronosRoot.Chronos, chronosRoot.Chronos.PostMessageUtilities, chronosRoot.Chronos.PostMessageChannelPolyfill);
}

return chronosRoot.Chronos.PostMessageChannel;
define("Chronos.PostMessageChannel", ["Chronos.PostMessageUtilities", "Chronos.PostMessageChannelPolyfill"], function (PostMessageUtilities, PostMessageChannelPolyfill) {
return factory(root, chronosRoot, PostMessageUtilities, PostMessageChannelPolyfill, true);
});
return;
}
Expand All @@ -24,9 +18,10 @@
* @depend ./PostMessageUtilities.js
* @depend ./PostMessageChannelPolyfill.js
*/
chronosRoot.Chronos = chronosRoot.Chronos || {};
factory(root, chronosRoot.Chronos, chronosRoot.Chronos.PostMessageUtilities, chronosRoot.Chronos.PostMessageChannelPolyfill);
}
}(this, typeof ChronosRoot === "undefined" ? this : ChronosRoot, function (root, exports, PostMessageUtilities, PostMessageChannelPolyfill) {
}(this, typeof ChronosRoot === "undefined" ? this : ChronosRoot, function (root, exports, PostMessageUtilities, PostMessageChannelPolyfill, hide) {
"use strict";

/*jshint validthis:true */
Expand Down Expand Up @@ -694,5 +689,8 @@

// attach properties to the exports object to define
// the exported module properties.
exports.PostMessageChannel = PostMessageChannel;
if (!hide) {
exports.PostMessageChannel = PostMessageChannel;
}
return PostMessageChannel;
}));
18 changes: 8 additions & 10 deletions src/courier/PostMessageChannelPolyfill.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
;(function (root, chronosRoot, factory) {
"use strict";

chronosRoot.Chronos = chronosRoot.Chronos || {};

/* istanbul ignore if */
//<amd>
if ("function" === typeof define && define.amd) {

// AMD. Register as an anonymous module.
define("Chronos.PostMessageChannelPolyfill", ["exports", "Chronos.PostMessageUtilities"], function () {
if (!chronosRoot.Chronos.PostMessageChannelPolyfill) {
factory(root, chronosRoot.Chronos, chronosRoot.Chronos.PostMessageUtilities);
}

return chronosRoot.Chronos.PostMessageChannelPolyfill;
define("Chronos.PostMessageChannelPolyfill", ["Chronos.PostMessageUtilities"], function (PostMessageUtilities) {
return factory(root, chronosRoot, PostMessageUtilities, true);
});
return;
}
Expand All @@ -23,9 +17,10 @@
/**
* @depend ./PostMessageUtilities.js
*/
chronosRoot.Chronos = chronosRoot.Chronos || {};
factory(root, chronosRoot.Chronos, chronosRoot.Chronos.PostMessageUtilities);
}
}(this, typeof ChronosRoot === "undefined" ? this : ChronosRoot, function (root, exports, PostMessageUtilities) {
}(this, typeof ChronosRoot === "undefined" ? this : ChronosRoot, function (root, exports, PostMessageUtilities, hide) {
"use strict";

/*jshint validthis:true */
Expand Down Expand Up @@ -174,5 +169,8 @@

// attach properties to the exports object to define
// the exported module properties.
exports.PostMessageChannelPolyfill = exports.PostMessageChannelPolyfill || PostMessageChannelPolyfill;
if (!hide) {
exports.PostMessageChannelPolyfill = exports.PostMessageChannelPolyfill || PostMessageChannelPolyfill;
}
return PostMessageChannelPolyfill;
}));
22 changes: 10 additions & 12 deletions src/courier/PostMessageCourier.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,15 @@
;(function (root, cacherRoot, circuitRoot, factory) {
"use strict";

root.Chronos = root.Chronos || {};

/* istanbul ignore if */
//<amd>
if ("function" === typeof define && define.amd) {

// AMD. Register as an anonymous module.
define("Chronos.PostMessageCourier", ["exports", "Chronos.PostMessageUtilities", "Chronos.Channels", "cacher", "CircuitBreaker", "Chronos.PostMessageChannel", "Chronos.PostMessagePromise", "Chronos.PostMessageMapper"], function () {
if (!root.Chronos.PostMessageCourier) {
factory(root, root.Chronos, root.Chronos.PostMessageUtilities, root.Chronos.Channels,
cacherRoot.Cacher, circuitRoot.CircuitBreaker,
root.Chronos.PostMessageChannel, root.Chronos.PostMessagePromise, root.Chronos.PostMessageMapper);
}

return root.Chronos.PostMessageCourier;
define("Chronos.PostMessageCourier", ["Chronos.PostMessageUtilities", "Chronos.Channels", "cacher", "CircuitBreaker", "Chronos.PostMessageChannel", "Chronos.PostMessagePromise", "Chronos.PostMessageMapper"],
function (PostMessageUtilities, Channels, cacher, CircuitBreaker, PostMessageChannel, PostMessagePromise, PostMessageMapper) {
return factory(root, root, PostMessageUtilities, Channels,
cacher, CircuitBreaker, PostMessageChannel, PostMessagePromise, PostMessageMapper, true);
});
return;
}
Expand All @@ -47,14 +41,15 @@
* @depend ./PostMessagePromise.js
* @depend ./PostMessageMapper.js
*/
root.Chronos = root.Chronos || {};
factory(root, root.Chronos, root.Chronos.PostMessageUtilities, root.Chronos.Channels,
cacherRoot.Cacher, circuitRoot.CircuitBreaker,
root.Chronos.PostMessageChannel, root.Chronos.PostMessagePromise, root.Chronos.PostMessageMapper);
}
}(typeof ChronosRoot === "undefined" ? this : ChronosRoot,
typeof CacherRoot === "undefined" ? this : CacherRoot,
typeof CircuitRoot === "undefined" ? this : CircuitRoot,
function (root, exports, PostMessageUtilities, Channels, Cacher, CircuitBreaker, PostMessageChannel, PostMessagePromise, PostMessageMapper) {
function (root, exports, PostMessageUtilities, Channels, Cacher, CircuitBreaker, PostMessageChannel, PostMessagePromise, PostMessageMapper, hide) {
"use strict";

/*jshint validthis:true */
Expand Down Expand Up @@ -750,5 +745,8 @@

// attach properties to the exports object to define
// the exported module properties.
exports.PostMessageCourier = exports.PostMessageCourier || PostMessageCourier;
if (!hide) {
exports.PostMessageCourier = exports.PostMessageCourier || PostMessageCourier;
}
return PostMessageCourier;
}));
18 changes: 8 additions & 10 deletions src/courier/PostMessageMapper.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
;(function (root, factory) {
"use strict";

root.Chronos = root.Chronos || {};

/* istanbul ignore if */
//<amd>
if ("function" === typeof define && define.amd) {

// AMD. Register as an anonymous module.
define("Chronos.PostMessageMapper", ["exports", "Chronos.PostMessageUtilities"], function () {
if (!root.Chronos.PostMessageMapper) {
factory(root, root.Chronos, root.Chronos.PostMessageUtilities);
}

return root.Chronos.PostMessageMapper;
define("Chronos.PostMessageMapper", ["Chronos.PostMessageUtilities"], function (PostMessageUtilities) {
return factory(root, root, PostMessageUtilities, true);
});
return;
}
Expand All @@ -23,9 +17,10 @@
/**
* @depend ./PostMessageUtilities.js
*/
root.Chronos = root.Chronos || {};
factory(root, root.Chronos, root.Chronos.PostMessageUtilities);
}
}(typeof ChronosRoot === "undefined" ? this : ChronosRoot, function (root, exports, PostMessageUtilities) {
}(typeof ChronosRoot === "undefined" ? this : ChronosRoot, function (root, exports, PostMessageUtilities, hide) {
"use strict";

/*jshint validthis:true */
Expand Down Expand Up @@ -127,5 +122,8 @@

// attach properties to the exports object to define
// the exported module properties.
exports.PostMessageMapper = exports.PostMessageMapper || PostMessageMapper;
if (!hide) {
exports.PostMessageMapper = exports.PostMessageMapper || PostMessageMapper;
}
return PostMessageMapper;
}));
17 changes: 7 additions & 10 deletions src/courier/PostMessagePromise.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
;(function (root, chronosRoot, factory) {
"use strict";

chronosRoot.Chronos = chronosRoot.Chronos || {};

/* istanbul ignore if */
//<amd>
if ("function" === typeof define && define.amd) {

// AMD. Register as an anonymous module.
define("Chronos.PostMessagePromise", ["exports"], function () {
if (!chronosRoot.Chronos.PostMessagePromise) {
factory(root, chronosRoot.Chronos);
}

return chronosRoot.Chronos.PostMessagePromise;
return factory(root, chronosRoot, true);
});
return;
}
//</amd>
/* istanbul ignore next */
if ("object" !== typeof exports) {
chronosRoot.Chronos = chronosRoot.Chronos || {};
factory(root, chronosRoot.Chronos);
}
}(this, typeof ChronosRoot === "undefined" ? this : ChronosRoot, function (root, exports) {
}(this, typeof ChronosRoot === "undefined" ? this : ChronosRoot, function (root, exports, hide) {
"use strict";

/*jshint validthis:true */
Expand Down Expand Up @@ -199,5 +193,8 @@

// attach properties to the exports object to define
// the exported module properties.
exports.PostMessagePromise = exports.PostMessagePromise || PostMessagePromise;
if (!hide) {
exports.PostMessagePromise = exports.PostMessagePromise || PostMessagePromise;
}
return PostMessagePromise;
}));
Loading

0 comments on commit e644791

Please sign in to comment.