From e73ec1f1e64f1025ac90f0c3a75da8f7a53151b1 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Mon, 24 Mar 2014 14:26:51 -0400 Subject: [PATCH 1/2] Revert "pr #72" This reverts commit 1c60743f9df1a41f60436e8633fded2d3d92ab42. --- package.json | 4 ---- src/client/cloak.js | 37 +++++++++++++++++++++---------------- test/lib/superSuite.js | 7 ++----- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 2af6870..511bb4a 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,5 @@ "grunt-contrib-nodeunit": "~0.2.2", "grunt-contrib-jshint": "~0.7.2", "express": "~3.4.8" - }, - "dependencies": { - "underscore": "~1.6.0", - "socket.io-client": "~0.9.16" } } diff --git a/src/client/cloak.js b/src/client/cloak.js index b30c342..de60213 100644 --- a/src/client/cloak.js +++ b/src/client/cloak.js @@ -1,19 +1,7 @@ /* cloak client */ -/* global module,console */ - -(function(global, factory) { - - if (typeof global.define === 'function' && global.define.amd) { - define(['underscore', 'socket.io-client'], factory); - } else if (typeof module === 'object' && module.exports) { - module.exports = factory( - require('underscore'), require('socket.io-client') - ); - } else { - global.cloak = factory(global._, global.io); - } +/* global cloak:true,module,io:true,console,_:true */ -})(this, function(_, io) { +(function() { var removeKey = function(val, key, obj) { delete obj[key]; @@ -30,6 +18,17 @@ var cloak = { + _setLibs: function(a, b) { + _ = a; + io = b; + }, + + /** + * Set configuration options for Cloak. These options will be applied + * immediately if Cloak has already been started (see `cloak.run`), and + * they will be referenced in all future calls to `clock.run` until + * overwritten. + */ configure: function(configArg) { // When specified, the `messages` option should trigger the complete @@ -227,5 +226,11 @@ }; - return createCloak(); -}); + if (typeof window === 'undefined') { + module.exports = createCloak; + } + else { + cloak = createCloak(); + } + +}()); diff --git a/test/lib/superSuite.js b/test/lib/superSuite.js index 284e5dd..27e8ffd 100644 --- a/test/lib/superSuite.js +++ b/test/lib/superSuite.js @@ -59,12 +59,9 @@ module.exports = { // function instead of doing it manually means clients // will be properly cleaned up after tests are done. createClient: function() { - var client; - - delete require.cache[require.resolve('../../src/client/cloak')]; - client = require('../../src/client/cloak'); + var client = createCloakClient(); + client._setLibs(_, io); clients.push(client); - return client; } From e1ac413ac8269a77eaa04c8424d934645e5b5dd9 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Sun, 23 Mar 2014 14:50:43 -0400 Subject: [PATCH 2/2] Define Cloak client with UMD pattern Implement a more explicit mechanism for defining the Cloak client in both "browser global" environments and Node.js. In addition, implement support for AMD environments. --- package.json | 4 ++++ src/client/cloak.js | 31 ++++++++++++++++--------------- test/lib/superSuite.js | 7 +++++-- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 511bb4a..2af6870 100644 --- a/package.json +++ b/package.json @@ -9,5 +9,9 @@ "grunt-contrib-nodeunit": "~0.2.2", "grunt-contrib-jshint": "~0.7.2", "express": "~3.4.8" + }, + "dependencies": { + "underscore": "~1.6.0", + "socket.io-client": "~0.9.16" } } diff --git a/src/client/cloak.js b/src/client/cloak.js index de60213..f10a922 100644 --- a/src/client/cloak.js +++ b/src/client/cloak.js @@ -1,7 +1,19 @@ /* cloak client */ -/* global cloak:true,module,io:true,console,_:true */ +/* global module,console */ + +(function(global, factory) { + + if (typeof global.define === 'function' && global.define.amd) { + define(['underscore', 'socket.io-client'], factory); + } else if (typeof module === 'object' && module.exports) { + module.exports = factory( + require('underscore'), require('socket.io-client') + ); + } else { + global.cloak = factory(global._, global.io); + } -(function() { +})(this, function(_, io) { var removeKey = function(val, key, obj) { delete obj[key]; @@ -18,11 +30,6 @@ var cloak = { - _setLibs: function(a, b) { - _ = a; - io = b; - }, - /** * Set configuration options for Cloak. These options will be applied * immediately if Cloak has already been started (see `cloak.run`), and @@ -226,11 +233,5 @@ }; - if (typeof window === 'undefined') { - module.exports = createCloak; - } - else { - cloak = createCloak(); - } - -}()); + return createCloak(); +}); diff --git a/test/lib/superSuite.js b/test/lib/superSuite.js index 27e8ffd..284e5dd 100644 --- a/test/lib/superSuite.js +++ b/test/lib/superSuite.js @@ -59,9 +59,12 @@ module.exports = { // function instead of doing it manually means clients // will be properly cleaned up after tests are done. createClient: function() { - var client = createCloakClient(); - client._setLibs(_, io); + var client; + + delete require.cache[require.resolve('../../src/client/cloak')]; + client = require('../../src/client/cloak'); clients.push(client); + return client; }