Permalink
Browse files

version 0.0.2

clean up UMD boilerplate
  • Loading branch information...
daniellmb committed Nov 25, 2013
1 parent 6b82b71 commit 799865454c82c1d576e218ae9d33b702305df2b2
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
@@ -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
@@ -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

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -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
@@ -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.