Skip to content
Browse files

version 0.0.2

clean up UMD boilerplate
  • Loading branch information...
1 parent 6b82b71 commit 799865454c82c1d576e218ae9d33b702305df2b2 @daniellmb committed
Showing with 88 additions and 95 deletions.
  1. +0 −9 History.md
  2. +1 −1 bower.json
  3. +2 −1 minpubsub.js
  4. +84 −83 minpubsub.src.js
  5. +1 −1 package.json
View
9 History.md
@@ -1,9 +0,0 @@
-0.0.1 / Feb 1, 2012
-==================
-
- * Added package.json and published to npm <http://search.npmjs.org/#/minpubsub>.
-
-0.0.1 / April 21, 2011
-==================
-
- * Initial release
View
2 bower.json
@@ -1,7 +1,7 @@
{
"name": "minpubsub",
"description": "198 byte publish/subscribe messaging micro-framework",
- "version": "0.0.1",
+ "version": "0.0.2",
"keywords": [
"publish",
"subscribe",
View
3 minpubsub.js
@@ -1 +1,2 @@
-(function(d){var MinPubSub={};var cache=d.c_||{};MinPubSub.publish=function(topic,args){var subs=cache[topic],len=subs?subs.length:0;while(len--){subs[len].apply(d,args||[])}};MinPubSub.subscribe=function(topic,callback){if(!cache[topic]){cache[topic]=[]}cache[topic].push(callback);return[topic,callback]};MinPubSub.unsubscribe=function(handle,callback){var subs=cache[callback?handle:handle[0]],callback=callback||handle[1],len=subs?subs.length:0;while(len--){if(subs[len]===callback){subs.splice(len,1)}}};if(typeof module==="object"&&typeof module.exports==="object"){module.exports=exports=MinPubSub}else if(typeof define==="function"&&define.amd){define(function(){return MinPubSub})}else if(typeof window==="object"){window.publish=MinPubSub.publish;window.subscribe=MinPubSub.subscribe;window.unsubscribe=MinPubSub.unsubscribe}})(window);
+(function(b){var a={},e=b.c_||{};a.publish=function(f,c){for(var a=e[f],d=a?a.length:0;d--;)a[d].apply(b,c||[])};a.subscribe=function(a,c){e[a]||(e[a]=[]);e[a].push(c);return[a,c]};a.unsubscribe=function(a,c){var b=e[c?a:a[0]];c=c||a[1];for(var d=b?b.length:0;d--;)b[d]===c&&b.splice(d,1)};"object"===typeof module&&module.exports?module.exports=exports=a:"function"===typeof define&&define.amd?define(function(){return a}):"object"===typeof b&&(b.publish=a.publish,b.subscribe=a.subscribe,b.unsubscribe=
+a.unsubscribe)})(this.window);
View
167 minpubsub.src.js
@@ -1,94 +1,95 @@
/*!
-* MinPubSub
-* Copyright(c) 2011 Daniel Lamb <daniellmb.com>
-* MIT Licensed
-*/
+ * MinPubSub
+ * Copyright(c) 2011 Daniel Lamb <daniellmb.com>
+ * MIT Licensed
+ */
+(function (context) {
+ var MinPubSub = {};
-(function(d){
- var MinPubSub = {};
+ // the topic/subscription hash
+ var cache = context.c_ || {}; //check for 'c_' cache for unit testing
- // the topic/subscription hash
- var cache = d.c_ || {}; //check for "c_" cache for unit testing
-
- MinPubSub.publish = function(/* String */ topic, /* Array? */ args){
- // summary:
- // Publish some data on a named topic.
- // topic: String
- // The channel to publish on
- // args: Array?
- // The data to publish. Each array item is converted into an ordered
- // arguments on the subscribed functions.
- //
- // example:
- // Publish stuff on '/some/topic'. Anything subscribed will be called
- // with a function signature like: function(a,b,c){ ... }
- //
- // publish("/some/topic", ["a","b","c"]);
-
- var subs = cache[topic],
- len = subs ? subs.length : 0;
+ MinPubSub.publish = function ( /* String */ topic, /* Array? */ args) {
+ // summary:
+ // Publish some data on a named topic.
+ // topic: String
+ // The channel to publish on
+ // args: Array?
+ // The data to publish. Each array item is converted into an ordered
+ // arguments on the subscribed functions.
+ //
+ // example:
+ // Publish stuff on '/some/topic'. Anything subscribed will be called
+ // with a function signature like: function(a,b,c){ ... }
+ //
+ // publish('/some/topic', ['a','b','c']);
- //can change loop or reverse array if the order matters
- while(len--){
- subs[len].apply(d, args || []);
- }
- };
+ var subs = cache[topic],
+ len = subs ? subs.length : 0;
- MinPubSub.subscribe = function(/* String */ topic, /* Function */ callback){
- // summary:
- // Register a callback on a named topic.
- // topic: String
- // The channel to subscribe to
- // callback: Function
- // The handler event. Anytime something is publish'ed on a
- // subscribed channel, the callback will be called with the
- // published array as ordered arguments.
- //
- // returns: Array
- // A handle which can be used to unsubscribe this particular subscription.
- //
- // example:
- // subscribe("/some/topic", function(a, b, c){ /* handle data */ });
+ //can change loop or reverse array if the order matters
+ while (len--) {
+ subs[len].apply(context, args || []);
+ }
+ };
- if(!cache[topic]){
- cache[topic] = [];
- }
- cache[topic].push(callback);
- return [topic, callback]; // Array
- };
+ MinPubSub.subscribe = function ( /* String */ topic, /* Function */ callback) {
+ // summary:
+ // Register a callback on a named topic.
+ // topic: String
+ // The channel to subscribe to
+ // callback: Function
+ // The handler event. Anytime something is publish'ed on a
+ // subscribed channel, the callback will be called with the
+ // published array as ordered arguments.
+ //
+ // returns: Array
+ // A handle which can be used to unsubscribe this particular subscription.
+ //
+ // example:
+ // subscribe('/some/topic', function(a, b, c){ /* handle data */ });
- MinPubSub.unsubscribe = function(/* Array */ handle, /* Function? */ callback){
- // summary:
- // Disconnect a subscribed function for a topic.
- // handle: Array
- // The return value from a subscribe call.
- // example:
- // var handle = subscribe("/some/topic", function(){});
- // unsubscribe(handle);
-
- var subs = cache[callback ? handle : handle[0]],
- callback = callback || handle[1],
- len = subs ? subs.length : 0;
-
- while(len--){
- if(subs[len] === callback){
- subs.splice(len, 1);
- }
- }
- };
+ if (!cache[topic]) {
+ cache[topic] = [];
+ }
+ cache[topic].push(callback);
+ return [topic, callback]; // Array
+ };
- // UMD definition to allow for CommonJS, AMD and legacy window
- if (typeof module === 'object' && typeof module.exports === 'object') {
- // CommonJS, just export
- module.exports = exports = MinPubSub;
+ MinPubSub.unsubscribe = function ( /* Array */ handle, /* Function? */ callback) {
+ // summary:
+ // Disconnect a subscribed function for a topic.
+ // handle: Array
+ // The return value from a subscribe call.
+ // example:
+ // var handle = subscribe('/some/topic', function(){});
+ // unsubscribe(handle);
+
+ var subs = cache[callback ? handle : handle[0]],
+ callback = callback || handle[1],
+ len = subs ? subs.length : 0;
+
+ while (len--) {
+ if (subs[len] === callback) {
+ subs.splice(len, 1);
+ }
+ }
+ };
+
+ // UMD definition to allow for CommonJS, AMD and legacy window
+ if (typeof module === 'object' && module.exports) {
+ // CommonJS, just export
+ module.exports = exports = MinPubSub;
} else if (typeof define === 'function' && define.amd) {
- // AMD support
- define(function () { return MinPubSub; });
- } else if (typeof window === 'object') {
- // If no AMD and we are in the browser, attach to window
- window.publish = MinPubSub.publish;
- window.subscribe = MinPubSub.subscribe;
- window.unsubscribe = MinPubSub.unsubscribe;
+ // AMD support
+ define(function () {
+ return MinPubSub;
+ });
+ } else if (typeof context === 'object') {
+ // If no AMD and we are in the browser, attach to window
+ context.publish = MinPubSub.publish;
+ context.subscribe = MinPubSub.subscribe;
+ context.unsubscribe = MinPubSub.unsubscribe;
}
-})(window);
+})(this.window);
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "minpubsub",
"description": "198 byte publish/subscribe messaging micro-framework",
- "version": "0.0.1",
+ "version": "0.0.2",
"keywords": [
"publish",
"subscribe",

0 comments on commit 7998654

Please sign in to comment.
Something went wrong with that request. Please try again.