diff --git a/CHANGELOG.md b/CHANGELOG.md index a31baac..bd30317 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,24 @@ +### [0.9.1](https://github.com/jmeas/backbone.radio/releases/tag/v0.8.2) + +- **Refactor**: Structure and build using babel-boilerplate +- Update Underscore and Backbone dependencies to 1.8.3 and 1.2.1 respectively to match Marionette. + +### [0.9.0](https://github.com/jmeas/backbone.radio/releases/tag/v0.9.0) + +- **Breaking change**: Space-separated requests no longer return an Array. Instead, an Object is returned. + ```js + // old + myChannel.request('thingOne thingTwo'); + // => [replyOne, replyTwo] + + // new + myChannel.request('thingOne thingTwo'); + // => { thingOne: replyOne, thingTwo: replyTwo } + ``` + +- **New feature**: `Radio.reset()` is now a top-level API method that can be used to reset a channel, or all channels. Do note that channels continue to have their own `reset` method. +- **New feature**: `Radio.debugLog()` is now exposed...go forth and customize how Radio logs potential errors! + ### [0.8.2](https://github.com/jmeas/backbone.radio/releases/tag/v0.8.2) - **Refactor**: A small refactor to support Underscore 1.4.4 (the lowest version that Marionette supports) diff --git a/bower.json b/bower.json index e84f2ce..b37c3e7 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "backbone.radio", - "version": "0.9.0", + "version": "0.9.1", "homepage": "https://github.com/marionettejs/backbone.radio", "authors": [ "Jmeas " diff --git a/build/backbone.radio.js b/build/backbone.radio.js index a281cff..49c6e70 100644 --- a/build/backbone.radio.js +++ b/build/backbone.radio.js @@ -1,27 +1,15 @@ -// Backbone.Radio v0.9.0 -(function(root, factory) { - if (typeof define === 'function' && define.amd) { - define(['backbone', 'underscore'], function(Backbone, _) { - return factory(Backbone, _); - }); - } - else if (typeof exports !== 'undefined') { - var Backbone = require('backbone'); - var _ = require('underscore'); - module.exports = factory(Backbone, _); - } - else { - factory(root.Backbone, root._); - } -}(this, function(Backbone, _) { - 'use strict'; +// Backbone.Radio v0.9.1 +(function (global, factory) { + typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory(require("underscore"), require("backbone")) : typeof define === "function" && define.amd ? define(["underscore", "backbone"], factory) : global.Backbone.Radio = factory(global._, global.Backbone); +})(this, function (_, Backbone) { + "use strict"; var previousRadio = Backbone.Radio; - + var Radio = Backbone.Radio = {}; - - Radio.VERSION = '0.9.0'; - + + Radio.VERSION = "0.9.1"; + // This allows you to run multiple instances of Radio on the same // webapp. After loading the new version, call `noConflict()` to // get a reference to it. At the same time the old version will be @@ -30,49 +18,48 @@ Backbone.Radio = previousRadio; return this; }; - + // Whether or not we're in DEBUG mode or not. DEBUG mode helps you // get around the issues of lack of warnings when events are mis-typed. Radio.DEBUG = false; - + // Format debug text. - Radio._debugText = function(warning, eventName, channelName) { - return warning + (channelName ? ' on the ' + channelName + ' channel' : '') + - ': "' + eventName + '"'; + Radio._debugText = function (warning, eventName, channelName) { + return warning + (channelName ? " on the " + channelName + " channel" : "") + ": \"" + eventName + "\""; }; - + // This is the method that's called when an unregistered event was called. // By default, it logs warning to the console. By overriding this you could // make it throw an Error, for instance. This would make firing a nonexistent event // have the same consequence as firing a nonexistent method on an Object. - Radio.debugLog = function(warning, eventName, channelName) { + Radio.debugLog = function (warning, eventName, channelName) { if (Radio.DEBUG && console && console.warn) { console.warn(Radio._debugText(warning, eventName, channelName)); } }; - + var eventSplitter = /\s+/; - + // An internal method used to handle Radio's method overloading for Requests and // Commands. It's borrowed from Backbone.Events. It differs from Backbone's overload // API (which is used in Backbone.Events) in that it doesn't support space-separated // event names. - Radio._eventsApi = function(obj, action, name, rest) { + Radio._eventsApi = function (obj, action, name, rest) { if (!name) { return false; } - + var results = {}; - + // Handle event maps. - if (typeof name === 'object') { + if (typeof name === "object") { for (var key in name) { var result = obj[action].apply(obj, [key, name[key]].concat(rest)); eventSplitter.test(key) ? _.extend(results, result) : results[key] = result; } return results; } - + // Handle space separated event names. if (eventSplitter.test(name)) { var names = name.split(eventSplitter); @@ -81,297 +68,303 @@ } return results; } - + return false; }; - + // An optimized way to execute callbacks. - Radio._callHandler = function(callback, context, args) { - var a1 = args[0], a2 = args[1], a3 = args[2]; - switch(args.length) { - case 0: return callback.call(context); - case 1: return callback.call(context, a1); - case 2: return callback.call(context, a1, a2); - case 3: return callback.call(context, a1, a2, a3); - default: return callback.apply(context, args); + Radio._callHandler = function (callback, context, args) { + var a1 = args[0], + a2 = args[1], + a3 = args[2]; + switch (args.length) { + case 0: + return callback.call(context); + case 1: + return callback.call(context, a1); + case 2: + return callback.call(context, a1, a2); + case 3: + return callback.call(context, a1, a2, a3); + default: + return callback.apply(context, args); } }; - + // A helper used by `off` methods to the handler from the store function removeHandler(store, name, callback, context) { var event = store[name]; - if ( - (!callback || (callback === event.callback || callback === event.callback._callback)) && - (!context || (context === event.context)) - ) { + if ((!callback || (callback === event.callback || callback === event.callback._callback)) && (!context || context === event.context)) { delete store[name]; return true; } } - + function removeHandlers(store, name, callback, context) { store || (store = {}); var names = name ? [name] : _.keys(store); var matched = false; - + for (var i = 0, length = names.length; i < length; i++) { name = names[i]; - + // If there's no event by this name, log it and continue // with the loop if (!store[name]) { continue; } - + if (removeHandler(store, name, callback, context)) { matched = true; } } - + return matched; } - + /* * tune-in * ------- * Get console logs of a channel's activity * */ - + var _logs = {}; - + // This is to produce an identical function in both tuneIn and tuneOut, // so that Backbone.Events unregisters it. function _partial(channelName) { return _logs[channelName] || (_logs[channelName] = _.partial(Radio.log, channelName)); } - + _.extend(Radio, { - + // Log information about the channel and event - log: function(channelName, eventName) { + log: function log(channelName, eventName) { var args = _.rest(arguments, 2); - console.log('[' + channelName + '] "' + eventName + '"', args); + console.log("[" + channelName + "] \"" + eventName + "\"", args); }, - + // Logs all events on this channel to the console. It sets an // internal value on the channel telling it we're listening, // then sets a listener on the Backbone.Events - tuneIn: function(channelName) { + tuneIn: function tuneIn(channelName) { var channel = Radio.channel(channelName); channel._tunedIn = true; - channel.on('all', _partial(channelName)); + channel.on("all", _partial(channelName)); return this; }, - + // Stop logging all of the activities on this channel to the console - tuneOut: function(channelName) { + tuneOut: function tuneOut(channelName) { var channel = Radio.channel(channelName); channel._tunedIn = false; - channel.off('all', _partial(channelName)); + channel.off("all", _partial(channelName)); delete _logs[channelName]; return this; } }); - + /* * Backbone.Radio.Commands * ----------------------- * A messaging system for sending orders. * */ - + Radio.Commands = { - + // Issue a command - command: function(name) { + command: function command(name) { var args = _.rest(arguments); - if (Radio._eventsApi(this, 'command', name, args)) { + if (Radio._eventsApi(this, "command", name, args)) { return this; } var channelName = this.channelName; var commands = this._commands; - + // Check if we should log the command, and if so, do it if (channelName && this._tunedIn) { Radio.log.apply(this, [channelName, name].concat(args)); } - + // If the command isn't handled, log it in DEBUG mode and exit - if (commands && (commands[name] || commands['default'])) { - var handler = commands[name] || commands['default']; + if (commands && (commands[name] || commands["default"])) { + var handler = commands[name] || commands["default"]; args = commands[name] ? args : arguments; Radio._callHandler(handler.callback, handler.context, args); } else { - Radio.debugLog('An unhandled command was fired', name, channelName); + Radio.debugLog("An unhandled command was fired", name, channelName); } - + return this; }, - + // Register a handler for a command. - comply: function(name, callback, context) { - if (Radio._eventsApi(this, 'comply', name, [callback, context])) { + comply: function comply(name, callback, context) { + if (Radio._eventsApi(this, "comply", name, [callback, context])) { return this; } this._commands || (this._commands = {}); - + if (this._commands[name]) { - Radio.debugLog('A command was overwritten', name, this.channelName); + Radio.debugLog("A command was overwritten", name, this.channelName); } - + this._commands[name] = { callback: callback, context: context || this }; - + return this; }, - + // Register a handler for a command that happens just once. - complyOnce: function(name, callback, context) { - if (Radio._eventsApi(this, 'complyOnce', name, [callback, context])) { + complyOnce: function complyOnce(name, callback, context) { + if (Radio._eventsApi(this, "complyOnce", name, [callback, context])) { return this; } var self = this; - - var once = _.once(function() { + + var once = _.once(function () { self.stopComplying(name); return callback.apply(this, arguments); }); - + return this.comply(name, once, context); }, - + // Remove handler(s) - stopComplying: function(name, callback, context) { - if (Radio._eventsApi(this, 'stopComplying', name)) { + stopComplying: function stopComplying(name, callback, context) { + if (Radio._eventsApi(this, "stopComplying", name)) { return this; } - + // Remove everything if there are no arguments passed if (!name && !callback && !context) { delete this._commands; } else if (!removeHandlers(this._commands, name, callback, context)) { - Radio.debugLog('Attempted to remove the unregistered command', name, this.channelName); + Radio.debugLog("Attempted to remove the unregistered command", name, this.channelName); } - + return this; } }; - + /* * Backbone.Radio.Requests * ----------------------- * A messaging system for requesting data. * */ - + function makeCallback(callback) { - return _.isFunction(callback) ? callback : function () { return callback; }; + return _.isFunction(callback) ? callback : function () { + return callback; + }; } - + Radio.Requests = { - + // Make a request - request: function(name) { + request: function request(name) { var args = _.rest(arguments); - var results = Radio._eventsApi(this, 'request', name, args); + var results = Radio._eventsApi(this, "request", name, args); if (results) { return results; } var channelName = this.channelName; var requests = this._requests; - + // Check if we should log the request, and if so, do it if (channelName && this._tunedIn) { Radio.log.apply(this, [channelName, name].concat(args)); } - + // If the request isn't handled, log it in DEBUG mode and exit - if (requests && (requests[name] || requests['default'])) { - var handler = requests[name] || requests['default']; + if (requests && (requests[name] || requests["default"])) { + var handler = requests[name] || requests["default"]; args = requests[name] ? args : arguments; return Radio._callHandler(handler.callback, handler.context, args); } else { - Radio.debugLog('An unhandled request was fired', name, channelName); + Radio.debugLog("An unhandled request was fired", name, channelName); } }, - + // Set up a handler for a request - reply: function(name, callback, context) { - if (Radio._eventsApi(this, 'reply', name, [callback, context])) { + reply: function reply(name, callback, context) { + if (Radio._eventsApi(this, "reply", name, [callback, context])) { return this; } - + this._requests || (this._requests = {}); - + if (this._requests[name]) { - Radio.debugLog('A request was overwritten', name, this.channelName); + Radio.debugLog("A request was overwritten", name, this.channelName); } - + this._requests[name] = { callback: makeCallback(callback), context: context || this }; - + return this; }, - + // Set up a handler that can only be requested once - replyOnce: function(name, callback, context) { - if (Radio._eventsApi(this, 'replyOnce', name, [callback, context])) { + replyOnce: function replyOnce(name, callback, context) { + if (Radio._eventsApi(this, "replyOnce", name, [callback, context])) { return this; } - + var self = this; - - var once = _.once(function() { + + var once = _.once(function () { self.stopReplying(name); return makeCallback(callback).apply(this, arguments); }); - + return this.reply(name, once, context); }, - + // Remove handler(s) - stopReplying: function(name, callback, context) { - if (Radio._eventsApi(this, 'stopReplying', name)) { + stopReplying: function stopReplying(name, callback, context) { + if (Radio._eventsApi(this, "stopReplying", name)) { return this; } - + // Remove everything if there are no arguments passed if (!name && !callback && !context) { delete this._requests; } else if (!removeHandlers(this._requests, name, callback, context)) { - Radio.debugLog('Attempted to remove the unregistered request', name, this.channelName); + Radio.debugLog("Attempted to remove the unregistered request", name, this.channelName); } - + return this; } }; - + /* * Backbone.Radio.channel * ---------------------- * Get a reference to a channel by name. * */ - + Radio._channels = {}; - - Radio.channel = function(channelName) { + + Radio.channel = function (channelName) { if (!channelName) { - throw new Error('You must provide a name for the channel.'); + throw new Error("You must provide a name for the channel."); } - + if (Radio._channels[channelName]) { return Radio._channels[channelName]; } else { - return (Radio._channels[channelName] = new Radio.Channel(channelName)); + return Radio._channels[channelName] = new Radio.Channel(channelName); } }; - + /* * Backbone.Radio.Channel * ---------------------- @@ -379,15 +372,15 @@ * Radio.Commands, and Radio.Requests. * */ - - Radio.Channel = function(channelName) { + + Radio.Channel = function (channelName) { this.channelName = channelName; }; - + _.extend(Radio.Channel.prototype, Backbone.Events, Radio.Commands, Radio.Requests, { - + // Remove all handlers from the messaging systems of this channel - reset: function() { + reset: function reset() { this.off(); this.stopListening(); this.stopComplying(); @@ -395,7 +388,7 @@ return this; } }); - + /* * Top-level API * ------------- @@ -403,24 +396,28 @@ * from Backbone.Radio. * */ - - var channel, args, systems = [Backbone.Events, Radio.Commands, Radio.Requests]; - - _.each(systems, function(system) { - _.each(system, function(method, methodName) { - Radio[methodName] = function(channelName) { + + var channel, + args, + systems = [Backbone.Events, Radio.Commands, Radio.Requests]; + + _.each(systems, function (system) { + _.each(system, function (method, methodName) { + Radio[methodName] = function (channelName) { args = _.rest(arguments); channel = this.channel(channelName); return channel[methodName].apply(channel, args); }; }); }); - - Radio.reset = function(channelName) { + + Radio.reset = function (channelName) { var channels = !channelName ? this._channels : [this._channels[channelName]]; - _.invoke(channels, 'reset'); + _.invoke(channels, "reset"); }; - - return Radio; -})); + var backbone_radio = Radio; + + return backbone_radio; +}); +//# sourceMappingURL=./backbone.radio.js.map \ No newline at end of file diff --git a/build/backbone.radio.js.map b/build/backbone.radio.js.map new file mode 100644 index 0000000..40b7823 --- /dev/null +++ b/build/backbone.radio.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["backbone.radio.js"],"names":[],"mappings":";AACA,AAAC,CAAA,UAAU,MAAM,EAAE,OAAO,EAAE;AAC1B,SAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,WAAW,GAAG,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,GACnI,OAAO,MAAM,KAAK,UAAU,IAAI,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC,YAAY,EAAE,UAAU,CAAC,EAAE,OAAO,CAAC,GACxF,MAAM,CAAC,QAAQ,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAA;CAC3D,CAAA,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,QAAQ,EAAE;AAAE,cAAY,CAAC;;AAE5C,MAAI,aAAa,GAAG,QAAQ,CAAC,KAAK,CAAC;;AAEnC,MAAI,KAAK,GAAG,QAAQ,CAAC,KAAK,GAAG,EAAE,CAAC;;AAEhC,OAAK,CAAC,OAAO,GAAG,OAAO,CAAC;;;;;;AAMxB,OAAK,CAAC,UAAU,GAAG,YAAY;AAC7B,YAAQ,CAAC,KAAK,GAAG,aAAa,CAAC;AAC/B,WAAO,IAAI,CAAC;GACb,CAAC;;;;AAIF,OAAK,CAAC,KAAK,GAAG,KAAK,CAAC;;;AAGpB,OAAK,CAAC,UAAU,GAAG,UAAS,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE;AAC3D,WAAO,O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I,CAAC,OAAO,EAAE,UAAS,MAAM,EAAE;AAC/B,KAAC,CAAC,IAAI,CAAC,MAAM,EAAE,UAAS,MAAM,EAAE,UAAU,EAAE;AAC1C,WAAK,CAAC,UAAU,CAAC,GAAG,UAAS,WAAW,EAAE;AACxC,YAAI,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACzB,eAAO,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;AACpC,eAAO,OAAO,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;OACjD,CAAC;KACH,CAAC,CAAC;GACJ,CAAC,CAAC;;AAEH,OAAK,CAAC,KAAK,GAAG,UAAS,WAAW,EAAE;AAClC,QAAI,QAAQ,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,SAAS,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;AAC7E,KAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;GAC7B,CAAC;;AAEF,MAAI,cAAc,GAAG,KAAK,CAAC;;AAE3B,SAAO,cAAc,CAAC;CAEvB,CAAC,CAAE","file":"backbone.radio.js","sourcesContent":["// Backbone.Radio v0.9.1\n(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('underscore'), require('backbone')) :\n typeof define === 'function' && define.amd ? define(['underscore', 'backbone'], factory) :\n global.Backbone.Radio = factory(global._, global.Backbone)\n}(this, function (_, Backbone) { 'use strict';\n\n var previousRadio = Backbone.Radio;\n\n var Radio = Backbone.Radio = {};\n\n Radio.VERSION = '0.9.1';\n\n // This allows you to run multiple instances of Radio on the same\n // webapp. After loading the new version, call `noConflict()` to\n // get a reference to it. At the same time the old version will be\n // returned to Backbone.Radio.\n Radio.noConflict = function () {\n Backbone.Radio = previousRadio;\n return this;\n };\n\n // Whether or not we're in DEBUG mode or not. DEBUG mode helps you\n // get around the issues of lack of warnings when events are mis-typed.\n Radio.DEBUG = false;\n\n // Format debug text.\n Radio._debugText = function(warning, eventName, channelName) {\n return warning + (channelName ? ' on the ' + channelName + ' channel' : '') +\n ': \"' + eventName + '\"';\n };\n\n // This is the method that's called when an unregistered event was called.\n // By default, it logs warning to the console. By overriding this you could\n // make it throw an Error, for instance. This would make firing a nonexistent event\n // have the same consequence as firing a nonexistent method on an Object.\n Radio.debugLog = function(warning, eventName, channelName) {\n if (Radio.DEBUG && console && console.warn) {\n console.warn(Radio._debugText(warning, eventName, channelName));\n }\n };\n\n var eventSplitter = /\\s+/;\n\n // An internal method used to handle Radio's method overloading for Requests and\n // Commands. It's borrowed from Backbone.Events. It differs from Backbone's overload\n // API (which is used in Backbone.Events) in that it doesn't support space-separated\n // event names.\n Radio._eventsApi = function(obj, action, name, rest) {\n if (!name) {\n return false;\n }\n\n var results = {};\n\n // Handle event maps.\n if (typeof name === 'object') {\n for (var key in name) {\n var result = obj[action].apply(obj, [key, name[key]].concat(rest));\n eventSplitter.test(key) ? _.extend(results, result) : results[key] = result;\n }\n return results;\n }\n\n // Handle space separated event names.\n if (eventSplitter.test(name)) {\n var names = name.split(eventSplitter);\n for (var i = 0, l = names.length; i < l; i++) {\n results[names[i]] = obj[action].apply(obj, [names[i]].concat(rest));\n }\n return results;\n }\n\n return false;\n };\n\n // An optimized way to execute callbacks.\n Radio._callHandler = function(callback, context, args) {\n var a1 = args[0], a2 = args[1], a3 = args[2];\n switch(args.length) {\n case 0: return callback.call(context);\n case 1: return callback.call(context, a1);\n case 2: return callback.call(context, a1, a2);\n case 3: return callback.call(context, a1, a2, a3);\n default: return callback.apply(context, args);\n }\n };\n\n // A helper used by `off` methods to the handler from the store\n function removeHandler(store, name, callback, context) {\n var event = store[name];\n if (\n (!callback || (callback === event.callback || callback === event.callback._callback)) &&\n (!context || (context === event.context))\n ) {\n delete store[name];\n return true;\n }\n }\n\n function removeHandlers(store, name, callback, context) {\n store || (store = {});\n var names = name ? [name] : _.keys(store);\n var matched = false;\n\n for (var i = 0, length = names.length; i < length; i++) {\n name = names[i];\n\n // If there's no event by this name, log it and continue\n // with the loop\n if (!store[name]) {\n continue;\n }\n\n if (removeHandler(store, name, callback, context)) {\n matched = true;\n }\n }\n\n return matched;\n }\n\n /*\n * tune-in\n * -------\n * Get console logs of a channel's activity\n *\n */\n\n var _logs = {};\n\n // This is to produce an identical function in both tuneIn and tuneOut,\n // so that Backbone.Events unregisters it.\n function _partial(channelName) {\n return _logs[channelName] || (_logs[channelName] = _.partial(Radio.log, channelName));\n }\n\n _.extend(Radio, {\n\n // Log information about the channel and event\n log: function(channelName, eventName) {\n var args = _.rest(arguments, 2);\n console.log('[' + channelName + '] \"' + eventName + '\"', args);\n },\n\n // Logs all events on this channel to the console. It sets an\n // internal value on the channel telling it we're listening,\n // then sets a listener on the Backbone.Events\n tuneIn: function(channelName) {\n var channel = Radio.channel(channelName);\n channel._tunedIn = true;\n channel.on('all', _partial(channelName));\n return this;\n },\n\n // Stop logging all of the activities on this channel to the console\n tuneOut: function(channelName) {\n var channel = Radio.channel(channelName);\n channel._tunedIn = false;\n channel.off('all', _partial(channelName));\n delete _logs[channelName];\n return this;\n }\n });\n\n /*\n * Backbone.Radio.Commands\n * -----------------------\n * A messaging system for sending orders.\n *\n */\n\n Radio.Commands = {\n\n // Issue a command\n command: function(name) {\n var args = _.rest(arguments);\n if (Radio._eventsApi(this, 'command', name, args)) {\n return this;\n }\n var channelName = this.channelName;\n var commands = this._commands;\n\n // Check if we should log the command, and if so, do it\n if (channelName && this._tunedIn) {\n Radio.log.apply(this, [channelName, name].concat(args));\n }\n\n // If the command isn't handled, log it in DEBUG mode and exit\n if (commands && (commands[name] || commands['default'])) {\n var handler = commands[name] || commands['default'];\n args = commands[name] ? args : arguments;\n Radio._callHandler(handler.callback, handler.context, args);\n } else {\n Radio.debugLog('An unhandled command was fired', name, channelName);\n }\n\n return this;\n },\n\n // Register a handler for a command.\n comply: function(name, callback, context) {\n if (Radio._eventsApi(this, 'comply', name, [callback, context])) {\n return this;\n }\n this._commands || (this._commands = {});\n\n if (this._commands[name]) {\n Radio.debugLog('A command was overwritten', name, this.channelName);\n }\n\n this._commands[name] = {\n callback: callback,\n context: context || this\n };\n\n return this;\n },\n\n // Register a handler for a command that happens just once.\n complyOnce: function(name, callback, context) {\n if (Radio._eventsApi(this, 'complyOnce', name, [callback, context])) {\n return this;\n }\n var self = this;\n\n var once = _.once(function() {\n self.stopComplying(name);\n return callback.apply(this, arguments);\n });\n\n return this.comply(name, once, context);\n },\n\n // Remove handler(s)\n stopComplying: function(name, callback, context) {\n if (Radio._eventsApi(this, 'stopComplying', name)) {\n return this;\n }\n\n // Remove everything if there are no arguments passed\n if (!name && !callback && !context) {\n delete this._commands;\n } else if (!removeHandlers(this._commands, name, callback, context)) {\n Radio.debugLog('Attempted to remove the unregistered command', name, this.channelName);\n }\n\n return this;\n }\n };\n\n /*\n * Backbone.Radio.Requests\n * -----------------------\n * A messaging system for requesting data.\n *\n */\n\n function makeCallback(callback) {\n return _.isFunction(callback) ? callback : function () { return callback; };\n }\n\n Radio.Requests = {\n\n // Make a request\n request: function(name) {\n var args = _.rest(arguments);\n var results = Radio._eventsApi(this, 'request', name, args);\n if (results) {\n return results;\n }\n var channelName = this.channelName;\n var requests = this._requests;\n\n // Check if we should log the request, and if so, do it\n if (channelName && this._tunedIn) {\n Radio.log.apply(this, [channelName, name].concat(args));\n }\n\n // If the request isn't handled, log it in DEBUG mode and exit\n if (requests && (requests[name] || requests['default'])) {\n var handler = requests[name] || requests['default'];\n args = requests[name] ? args : arguments;\n return Radio._callHandler(handler.callback, handler.context, args);\n } else {\n Radio.debugLog('An unhandled request was fired', name, channelName);\n }\n },\n\n // Set up a handler for a request\n reply: function(name, callback, context) {\n if (Radio._eventsApi(this, 'reply', name, [callback, context])) {\n return this;\n }\n\n this._requests || (this._requests = {});\n\n if (this._requests[name]) {\n Radio.debugLog('A request was overwritten', name, this.channelName);\n }\n\n this._requests[name] = {\n callback: makeCallback(callback),\n context: context || this\n };\n\n return this;\n },\n\n // Set up a handler that can only be requested once\n replyOnce: function(name, callback, context) {\n if (Radio._eventsApi(this, 'replyOnce', name, [callback, context])) {\n return this;\n }\n\n var self = this;\n\n var once = _.once(function() {\n self.stopReplying(name);\n return makeCallback(callback).apply(this, arguments);\n });\n\n return this.reply(name, once, context);\n },\n\n // Remove handler(s)\n stopReplying: function(name, callback, context) {\n if (Radio._eventsApi(this, 'stopReplying', name)) {\n return this;\n }\n\n // Remove everything if there are no arguments passed\n if (!name && !callback && !context) {\n delete this._requests;\n } else if (!removeHandlers(this._requests, name, callback, context)) {\n Radio.debugLog('Attempted to remove the unregistered request', name, this.channelName);\n }\n\n return this;\n }\n };\n\n /*\n * Backbone.Radio.channel\n * ----------------------\n * Get a reference to a channel by name.\n *\n */\n\n Radio._channels = {};\n\n Radio.channel = function(channelName) {\n if (!channelName) {\n throw new Error('You must provide a name for the channel.');\n }\n\n if (Radio._channels[channelName]) {\n return Radio._channels[channelName];\n } else {\n return (Radio._channels[channelName] = new Radio.Channel(channelName));\n }\n };\n\n /*\n * Backbone.Radio.Channel\n * ----------------------\n * A Channel is an object that extends from Backbone.Events,\n * Radio.Commands, and Radio.Requests.\n *\n */\n\n Radio.Channel = function(channelName) {\n this.channelName = channelName;\n };\n\n _.extend(Radio.Channel.prototype, Backbone.Events, Radio.Commands, Radio.Requests, {\n\n // Remove all handlers from the messaging systems of this channel\n reset: function() {\n this.off();\n this.stopListening();\n this.stopComplying();\n this.stopReplying();\n return this;\n }\n });\n\n /*\n * Top-level API\n * -------------\n * Supplies the 'top-level API' for working with Channels directly\n * from Backbone.Radio.\n *\n */\n\n var channel, args, systems = [Backbone.Events, Radio.Commands, Radio.Requests];\n\n _.each(systems, function(system) {\n _.each(system, function(method, methodName) {\n Radio[methodName] = function(channelName) {\n args = _.rest(arguments);\n channel = this.channel(channelName);\n return channel[methodName].apply(channel, args);\n };\n });\n });\n\n Radio.reset = function(channelName) {\n var channels = !channelName ? this._channels : [this._channels[channelName]];\n _.invoke(channels, 'reset');\n };\n\n var backbone_radio = Radio;\n\n return backbone_radio;\n\n}));\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/build/backbone.radio.min.js b/build/backbone.radio.min.js index c108947..5094418 100644 --- a/build/backbone.radio.min.js +++ b/build/backbone.radio.min.js @@ -1,4 +1,3 @@ -// Backbone.Radio v0.9.0 - -!function(a,b){if("function"==typeof define&&define.amd)define(["backbone","underscore"],function(a,c){return b(a,c)});else if("undefined"!=typeof exports){var c=require("backbone"),d=require("underscore");module.exports=b(c,d)}else b(a.Backbone,a._)}(this,function(a,b){"use strict";function c(a,b,c,d){var e=a[b];return c&&c!==e.callback&&c!==e.callback._callback||d&&d!==e.context?void 0:(delete a[b],!0)}function d(a,d,e,f){a||(a={});for(var g=d?[d]:b.keys(a),h=!1,i=0,j=g.length;j>i;i++)d=g[i],a[d]&&c(a,d,e,f)&&(h=!0);return h}function e(a){return j[a]||(j[a]=b.partial(h.log,a))}function f(a){return b.isFunction(a)?a:function(){return a}}var g=a.Radio,h=a.Radio={};h.VERSION="0.9.0",h.noConflict=function(){return a.Radio=g,this},h.DEBUG=!1,h._debugText=function(a,b,c){return a+(c?" on the "+c+" channel":"")+': "'+b+'"'},h.debugLog=function(a,b,c){h.DEBUG&&console&&console.warn&&console.warn(h._debugText(a,b,c))};var i=/\s+/;h._eventsApi=function(a,c,d,e){if(!d)return!1;var f={};if("object"==typeof d){for(var g in d){var h=a[c].apply(a,[g,d[g]].concat(e));i.test(g)?b.extend(f,h):f[g]=h}return f}if(i.test(d)){for(var j=d.split(i),k=0,l=j.length;l>k;k++)f[j[k]]=a[c].apply(a,[j[k]].concat(e));return f}return!1},h._callHandler=function(a,b,c){var d=c[0],e=c[1],f=c[2];switch(c.length){case 0:return a.call(b);case 1:return a.call(b,d);case 2:return a.call(b,d,e);case 3:return a.call(b,d,e,f);default:return a.apply(b,c)}};var j={};b.extend(h,{log:function(a,c){var d=b.rest(arguments,2);console.log("["+a+'] "'+c+'"',d)},tuneIn:function(a){var b=h.channel(a);return b._tunedIn=!0,b.on("all",e(a)),this},tuneOut:function(a){var b=h.channel(a);return b._tunedIn=!1,b.off("all",e(a)),delete j[a],this}}),h.Commands={command:function(a){var c=b.rest(arguments);if(h._eventsApi(this,"command",a,c))return this;var d=this.channelName,e=this._commands;if(d&&this._tunedIn&&h.log.apply(this,[d,a].concat(c)),e&&(e[a]||e["default"])){var f=e[a]||e["default"];c=e[a]?c:arguments,h._callHandler(f.callback,f.context,c)}else h.debugLog("An unhandled command was fired",a,d);return this},comply:function(a,b,c){return h._eventsApi(this,"comply",a,[b,c])?this:(this._commands||(this._commands={}),this._commands[a]&&h.debugLog("A command was overwritten",a,this.channelName),this._commands[a]={callback:b,context:c||this},this)},complyOnce:function(a,c,d){if(h._eventsApi(this,"complyOnce",a,[c,d]))return this;var e=this,f=b.once(function(){return e.stopComplying(a),c.apply(this,arguments)});return this.comply(a,f,d)},stopComplying:function(a,b,c){return h._eventsApi(this,"stopComplying",a)?this:(a||b||c?d(this._commands,a,b,c)||h.debugLog("Attempted to remove the unregistered command",a,this.channelName):delete this._commands,this)}},h.Requests={request:function(a){var c=b.rest(arguments),d=h._eventsApi(this,"request",a,c);if(d)return d;var e=this.channelName,f=this._requests;if(e&&this._tunedIn&&h.log.apply(this,[e,a].concat(c)),f&&(f[a]||f["default"])){var g=f[a]||f["default"];return c=f[a]?c:arguments,h._callHandler(g.callback,g.context,c)}h.debugLog("An unhandled request was fired",a,e)},reply:function(a,b,c){return h._eventsApi(this,"reply",a,[b,c])?this:(this._requests||(this._requests={}),this._requests[a]&&h.debugLog("A request was overwritten",a,this.channelName),this._requests[a]={callback:f(b),context:c||this},this)},replyOnce:function(a,c,d){if(h._eventsApi(this,"replyOnce",a,[c,d]))return this;var e=this,g=b.once(function(){return e.stopReplying(a),f(c).apply(this,arguments)});return this.reply(a,g,d)},stopReplying:function(a,b,c){return h._eventsApi(this,"stopReplying",a)?this:(a||b||c?d(this._requests,a,b,c)||h.debugLog("Attempted to remove the unregistered request",a,this.channelName):delete this._requests,this)}},h._channels={},h.channel=function(a){if(!a)throw new Error("You must provide a name for the channel.");return h._channels[a]?h._channels[a]:h._channels[a]=new h.Channel(a)},h.Channel=function(a){this.channelName=a},b.extend(h.Channel.prototype,a.Events,h.Commands,h.Requests,{reset:function(){return this.off(),this.stopListening(),this.stopComplying(),this.stopReplying(),this}});var k,l,m=[a.Events,h.Commands,h.Requests];return b.each(m,function(a){b.each(a,function(a,c){h[c]=function(a){return l=b.rest(arguments),k=this.channel(a),k[c].apply(k,l)}})}),h.reset=function(a){var c=a?[this._channels[a]]:this._channels;b.invoke(c,"reset")},h}); +// Backbone.Radio v0.9.1 +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("underscore"),require("backbone")):"function"==typeof define&&define.amd?define(["underscore","backbone"],t):e.Backbone.Radio=t(e._,e.Backbone)}(this,function(e,t){"use strict";function n(e,t,n,s){var r=e[t];return n&&n!==r.callback&&n!==r.callback._callback||s&&s!==r.context?void 0:(delete e[t],!0)}function s(t,s,r,i){t||(t={});for(var a=s?[s]:e.keys(t),o=!1,c=0,u=a.length;u>c;c++)s=a[c],t[s]&&n(t,s,r,i)&&(o=!0);return o}function r(t){return u[t]||(u[t]=e.partial(o.log,t))}function i(t){return e.isFunction(t)?t:function(){return t}}var a=t.Radio,o=t.Radio={};o.VERSION="0.9.1",o.noConflict=function(){return t.Radio=a,this},o.DEBUG=!1,o._debugText=function(e,t,n){return e+(n?" on the "+n+" channel":"")+': "'+t+'"'},o.debugLog=function(e,t,n){o.DEBUG&&console&&console.warn&&console.warn(o._debugText(e,t,n))};var c=/\s+/;o._eventsApi=function(t,n,s,r){if(!s)return!1;var i={};if("object"==typeof s){for(var a in s){var o=t[n].apply(t,[a,s[a]].concat(r));c.test(a)?e.extend(i,o):i[a]=o}return i}if(c.test(s)){for(var u=s.split(c),l=0,h=u.length;h>l;l++)i[u[l]]=t[n].apply(t,[u[l]].concat(r));return i}return!1},o._callHandler=function(e,t,n){var s=n[0],r=n[1],i=n[2];switch(n.length){case 0:return e.call(t);case 1:return e.call(t,s);case 2:return e.call(t,s,r);case 3:return e.call(t,s,r,i);default:return e.apply(t,n)}};var u={};e.extend(o,{log:function(t,n){var s=e.rest(arguments,2);console.log("["+t+'] "'+n+'"',s)},tuneIn:function(e){var t=o.channel(e);return t._tunedIn=!0,t.on("all",r(e)),this},tuneOut:function(e){var t=o.channel(e);return t._tunedIn=!1,t.off("all",r(e)),delete u[e],this}}),o.Commands={command:function(t){var n=e.rest(arguments);if(o._eventsApi(this,"command",t,n))return this;var s=this.channelName,r=this._commands;if(s&&this._tunedIn&&o.log.apply(this,[s,t].concat(n)),r&&(r[t]||r["default"])){var i=r[t]||r["default"];n=r[t]?n:arguments,o._callHandler(i.callback,i.context,n)}else o.debugLog("An unhandled command was fired",t,s);return this},comply:function(e,t,n){return o._eventsApi(this,"comply",e,[t,n])?this:(this._commands||(this._commands={}),this._commands[e]&&o.debugLog("A command was overwritten",e,this.channelName),this._commands[e]={callback:t,context:n||this},this)},complyOnce:function(t,n,s){if(o._eventsApi(this,"complyOnce",t,[n,s]))return this;var r=this,i=e.once(function(){return r.stopComplying(t),n.apply(this,arguments)});return this.comply(t,i,s)},stopComplying:function(e,t,n){return o._eventsApi(this,"stopComplying",e)?this:(e||t||n?s(this._commands,e,t,n)||o.debugLog("Attempted to remove the unregistered command",e,this.channelName):delete this._commands,this)}},o.Requests={request:function(t){var n=e.rest(arguments),s=o._eventsApi(this,"request",t,n);if(s)return s;var r=this.channelName,i=this._requests;if(r&&this._tunedIn&&o.log.apply(this,[r,t].concat(n)),i&&(i[t]||i["default"])){var a=i[t]||i["default"];return n=i[t]?n:arguments,o._callHandler(a.callback,a.context,n)}o.debugLog("An unhandled request was fired",t,r)},reply:function(e,t,n){return o._eventsApi(this,"reply",e,[t,n])?this:(this._requests||(this._requests={}),this._requests[e]&&o.debugLog("A request was overwritten",e,this.channelName),this._requests[e]={callback:i(t),context:n||this},this)},replyOnce:function(t,n,s){if(o._eventsApi(this,"replyOnce",t,[n,s]))return this;var r=this,a=e.once(function(){return r.stopReplying(t),i(n).apply(this,arguments)});return this.reply(t,a,s)},stopReplying:function(e,t,n){return o._eventsApi(this,"stopReplying",e)?this:(e||t||n?s(this._requests,e,t,n)||o.debugLog("Attempted to remove the unregistered request",e,this.channelName):delete this._requests,this)}},o._channels={},o.channel=function(e){if(!e)throw new Error("You must provide a name for the channel.");return o._channels[e]?o._channels[e]:o._channels[e]=new o.Channel(e)},o.Channel=function(e){this.channelName=e},e.extend(o.Channel.prototype,t.Events,o.Commands,o.Requests,{reset:function(){return this.off(),this.stopListening(),this.stopComplying(),this.stopReplying(),this}});var l,h,d=[t.Events,o.Commands,o.Requests];e.each(d,function(t){e.each(t,function(t,n){o[n]=function(t){return h=e.rest(arguments),l=this.channel(t),l[n].apply(l,h)}})}),o.reset=function(t){var n=t?[this._channels[t]]:this._channels;e.invoke(n,"reset")};var f=o;return f}); //# sourceMappingURL=backbone.radio.min.js.map \ No newline at end of file diff --git a/build/backbone.radio.min.js.map b/build/backbone.radio.min.js.map index 731b999..22efc32 100644 --- a/build/backbone.radio.min.js.map +++ b/build/backbone.radio.min.js.map @@ -1 +1,2 @@ -{"version":3,"file":"backbone.radio.min.js","sources":["backbone.radio.js"],"names":["root","factory","define","amd","Backbone","_","exports","require","module","this","removeHandler","store","name","callback","context","event","_callback","removeHandlers","names","keys","matched","i","length","_partial","channelName","_logs","partial","Radio","log","makeCallback","isFunction","previousRadio","VERSION","noConflict","DEBUG","_debugText","warning","eventName","debugLog","console","warn","eventSplitter","_eventsApi","obj","action","rest","results","key","result","apply","concat","test","extend","split","l","_callHandler","args","a1","a2","a3","call","arguments","tuneIn","channel","_tunedIn","on","tuneOut","off","Commands","command","commands","_commands","handler","comply","complyOnce","self","once","stopComplying","Requests","request","requests","_requests","reply","replyOnce","stopReplying","_channels","Error","Channel","prototype","Events","reset","st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AAQvC,GAChBuC,EAAQiC,GAAY/C,MAAMc,EAASP,QAKhD7B,EAAM+D,MAAQ,SAASlE,GACrB,GAAIyE,GAAYzE,GAAgCf,KAAK4E,UAAU7D,IAAjCf,KAAK4E,SACnChF,GAAE6F,OAAOD,EAAU,UAIdtE"} \ No newline at end of file +// Backbone.Radio v0.9.1 +{"version":3,"file":"backbone.radio.js","sources":["backbone.radio.js","/source/backbone.radio.js"],"names":["global","factory","exports","module","require","define","amd","Backbone","Radio","_","this","removeHandler","store","name","callback","context","event","_callback","removeHandlers","names","keys","matched","i","length","_partial","channelName","_logs","partial","log","makeCallback","isFunction","previousRadio","VERSION","noConflict","DEBUG","_debugText","warning","eventName","debugLog","console","warn","eventSplitter","_eventsApi","obj","action","rest","results","key","result","apply","concat","test","extend","split","l","_callHandler","args","a1","a2","a3","call","arguments","tuneIn","channel","_tunedIn","on","tuneOut","off","Commands","command","commands","_commands","handler","comply","complyOnce","self","once","stopComplying","Requests","request","requests","_requests","reply","replyOnce","stopReplying","_channels","Error","Channel","prototype","Events","reset","stopListening","systems","each","system","method","methodName","channels","invoke","backbone_radio"],"mappings":"CCCC,SAAUA,EAAQC,GACE,gBAAZC,UAA0C,mBAAXC,QAAyBA,OAAOD,QAAUD,EAAQG,QAAQ,cAAeA,QAAQ,aACrG,kBAAXC,SAAyBA,OAAOC,IAAMD,QAAQ,aAAc,YAAaJ,GAChFD,EAAOO,SAASC,MAAQP,EAAQD,EAAOS,EAAGT,EAAOO,WACjDG,KAAM,SAAUD,EAAGF,GAAY,YAoF/B,SAASI,GAAcC,EAAOC,EAAMC,EAAUC,GAC5C,GAAIC,GAAQJ,EAAMC,EAClB,OACKC,IAAaA,IAAaE,EAAMF,UAAYA,IAAaE,EAAMF,SAASG,WACxEF,GAAYA,IAAYC,EAAMD,QAFnC,cAISH,GAAMC,IACN,GAIX,QAASK,GAAeN,EAAOC,EAAMC,EAAUC,GAC7CH,IAAUA,KAIV,KAAK,GAHDO,GAAQN,GAAQA,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AC;;AAE3B,SAAO,cAAc,CAAC;CAEvB,CAAC,CAAE","sourceRoot":"/source/","sourcesContent":["// Backbone.Radio v0.9.1\n(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('underscore'), require('backbone')) :\n typeof define === 'function' && define.amd ? define(['underscore', 'backbone'], factory) :\n global.Backbone.Radio = factory(global._, global.Backbone)\n}(this, function (_, Backbone) { 'use strict';\n\n var previousRadio = Backbone.Radio;\n\n var Radio = Backbone.Radio = {};\n\n Radio.VERSION = '0.9.1';\n\n // This allows you to run multiple instances of Radio on the same\n // webapp. After loading the new version, call `noConflict()` to\n // get a reference to it. At the same time the old version will be\n // returned to Backbone.Radio.\n Radio.noConflict = function () {\n Backbone.Radio = previousRadio;\n return this;\n };\n\n // Whether or not we're in DEBUG mode or not. DEBUG mode helps you\n // get around the issues of lack of warnings when events are mis-typed.\n Radio.DEBUG = false;\n\n // Format debug text.\n Radio._debugText = function(warning, eventName, channelName) {\n return warning + (channelName ? ' on the ' + channelName + ' channel' : '') +\n ': \"' + eventName + '\"';\n };\n\n // This is the method that's called when an unregistered event was called.\n // By default, it logs warning to the console. By overriding this you could\n // make it throw an Error, for instance. This would make firing a nonexistent event\n // have the same consequence as firing a nonexistent method on an Object.\n Radio.debugLog = function(warning, eventName, channelName) {\n if (Radio.DEBUG && console && console.warn) {\n console.warn(Radio._debugText(warning, eventName, channelName));\n }\n };\n\n var eventSplitter = /\\s+/;\n\n // An internal method used to handle Radio's method overloading for Requests and\n // Commands. It's borrowed from Backbone.Events. It differs from Backbone's overload\n // API (which is used in Backbone.Events) in that it doesn't support space-separated\n // event names.\n Radio._eventsApi = function(obj, action, name, rest) {\n if (!name) {\n return false;\n }\n\n var results = {};\n\n // Handle event maps.\n if (typeof name === 'object') {\n for (var key in name) {\n var result = obj[action].apply(obj, [key, name[key]].concat(rest));\n eventSplitter.test(key) ? _.extend(results, result) : results[key] = result;\n }\n return results;\n }\n\n // Handle space separated event names.\n if (eventSplitter.test(name)) {\n var names = name.split(eventSplitter);\n for (var i = 0, l = names.length; i < l; i++) {\n results[names[i]] = obj[action].apply(obj, [names[i]].concat(rest));\n }\n return results;\n }\n\n return false;\n };\n\n // An optimized way to execute callbacks.\n Radio._callHandler = function(callback, context, args) {\n var a1 = args[0], a2 = args[1], a3 = args[2];\n switch(args.length) {\n case 0: return callback.call(context);\n case 1: return callback.call(context, a1);\n case 2: return callback.call(context, a1, a2);\n case 3: return callback.call(context, a1, a2, a3);\n default: return callback.apply(context, args);\n }\n };\n\n // A helper used by `off` methods to the handler from the store\n function removeHandler(store, name, callback, context) {\n var event = store[name];\n if (\n (!callback || (callback === event.callback || callback === event.callback._callback)) &&\n (!context || (context === event.context))\n ) {\n delete store[name];\n return true;\n }\n }\n\n function removeHandlers(store, name, callback, context) {\n store || (store = {});\n var names = name ? [name] : _.keys(store);\n var matched = false;\n\n for (var i = 0, length = names.length; i < length; i++) {\n name = names[i];\n\n // If there's no event by this name, log it and continue\n // with the loop\n if (!store[name]) {\n continue;\n }\n\n if (removeHandler(store, name, callback, context)) {\n matched = true;\n }\n }\n\n return matched;\n }\n\n /*\n * tune-in\n * -------\n * Get console logs of a channel's activity\n *\n */\n\n var _logs = {};\n\n // This is to produce an identical function in both tuneIn and tuneOut,\n // so that Backbone.Events unregisters it.\n function _partial(channelName) {\n return _logs[channelName] || (_logs[channelName] = _.partial(Radio.log, channelName));\n }\n\n _.extend(Radio, {\n\n // Log information about the channel and event\n log: function(channelName, eventName) {\n var args = _.rest(arguments, 2);\n console.log('[' + channelName + '] \"' + eventName + '\"', args);\n },\n\n // Logs all events on this channel to the console. It sets an\n // internal value on the channel telling it we're listening,\n // then sets a listener on the Backbone.Events\n tuneIn: function(channelName) {\n var channel = Radio.channel(channelName);\n channel._tunedIn = true;\n channel.on('all', _partial(channelName));\n return this;\n },\n\n // Stop logging all of the activities on this channel to the console\n tuneOut: function(channelName) {\n var channel = Radio.channel(channelName);\n channel._tunedIn = false;\n channel.off('all', _partial(channelName));\n delete _logs[channelName];\n return this;\n }\n });\n\n /*\n * Backbone.Radio.Commands\n * -----------------------\n * A messaging system for sending orders.\n *\n */\n\n Radio.Commands = {\n\n // Issue a command\n command: function(name) {\n var args = _.rest(arguments);\n if (Radio._eventsApi(this, 'command', name, args)) {\n return this;\n }\n var channelName = this.channelName;\n var commands = this._commands;\n\n // Check if we should log the command, and if so, do it\n if (channelName && this._tunedIn) {\n Radio.log.apply(this, [channelName, name].concat(args));\n }\n\n // If the command isn't handled, log it in DEBUG mode and exit\n if (commands && (commands[name] || commands['default'])) {\n var handler = commands[name] || commands['default'];\n args = commands[name] ? args : arguments;\n Radio._callHandler(handler.callback, handler.context, args);\n } else {\n Radio.debugLog('An unhandled command was fired', name, channelName);\n }\n\n return this;\n },\n\n // Register a handler for a command.\n comply: function(name, callback, context) {\n if (Radio._eventsApi(this, 'comply', name, [callback, context])) {\n return this;\n }\n this._commands || (this._commands = {});\n\n if (this._commands[name]) {\n Radio.debugLog('A command was overwritten', name, this.channelName);\n }\n\n this._commands[name] = {\n callback: callback,\n context: context || this\n };\n\n return this;\n },\n\n // Register a handler for a command that happens just once.\n complyOnce: function(name, callback, context) {\n if (Radio._eventsApi(this, 'complyOnce', name, [callback, context])) {\n return this;\n }\n var self = this;\n\n var once = _.once(function() {\n self.stopComplying(name);\n return callback.apply(this, arguments);\n });\n\n return this.comply(name, once, context);\n },\n\n // Remove handler(s)\n stopComplying: function(name, callback, context) {\n if (Radio._eventsApi(this, 'stopComplying', name)) {\n return this;\n }\n\n // Remove everything if there are no arguments passed\n if (!name && !callback && !context) {\n delete this._commands;\n } else if (!removeHandlers(this._commands, name, callback, context)) {\n Radio.debugLog('Attempted to remove the unregistered command', name, this.channelName);\n }\n\n return this;\n }\n };\n\n /*\n * Backbone.Radio.Requests\n * -----------------------\n * A messaging system for requesting data.\n *\n */\n\n function makeCallback(callback) {\n return _.isFunction(callback) ? callback : function () { return callback; };\n }\n\n Radio.Requests = {\n\n // Make a request\n request: function(name) {\n var args = _.rest(arguments);\n var results = Radio._eventsApi(this, 'request', name, args);\n if (results) {\n return results;\n }\n var channelName = this.channelName;\n var requests = this._requests;\n\n // Check if we should log the request, and if so, do it\n if (channelName && this._tunedIn) {\n Radio.log.apply(this, [channelName, name].concat(args));\n }\n\n // If the request isn't handled, log it in DEBUG mode and exit\n if (requests && (requests[name] || requests['default'])) {\n var handler = requests[name] || requests['default'];\n args = requests[name] ? args : arguments;\n return Radio._callHandler(handler.callback, handler.context, args);\n } else {\n Radio.debugLog('An unhandled request was fired', name, channelName);\n }\n },\n\n // Set up a handler for a request\n reply: function(name, callback, context) {\n if (Radio._eventsApi(this, 'reply', name, [callback, context])) {\n return this;\n }\n\n this._requests || (this._requests = {});\n\n if (this._requests[name]) {\n Radio.debugLog('A request was overwritten', name, this.channelName);\n }\n\n this._requests[name] = {\n callback: makeCallback(callback),\n context: context || this\n };\n\n return this;\n },\n\n // Set up a handler that can only be requested once\n replyOnce: function(name, callback, context) {\n if (Radio._eventsApi(this, 'replyOnce', name, [callback, context])) {\n return this;\n }\n\n var self = this;\n\n var once = _.once(function() {\n self.stopReplying(name);\n return makeCallback(callback).apply(this, arguments);\n });\n\n return this.reply(name, once, context);\n },\n\n // Remove handler(s)\n stopReplying: function(name, callback, context) {\n if (Radio._eventsApi(this, 'stopReplying', name)) {\n return this;\n }\n\n // Remove everything if there are no arguments passed\n if (!name && !callback && !context) {\n delete this._requests;\n } else if (!removeHandlers(this._requests, name, callback, context)) {\n Radio.debugLog('Attempted to remove the unregistered request', name, this.channelName);\n }\n\n return this;\n }\n };\n\n /*\n * Backbone.Radio.channel\n * ----------------------\n * Get a reference to a channel by name.\n *\n */\n\n Radio._channels = {};\n\n Radio.channel = function(channelName) {\n if (!channelName) {\n throw new Error('You must provide a name for the channel.');\n }\n\n if (Radio._channels[channelName]) {\n return Radio._channels[channelName];\n } else {\n return (Radio._channels[channelName] = new Radio.Channel(channelName));\n }\n };\n\n /*\n * Backbone.Radio.Channel\n * ----------------------\n * A Channel is an object that extends from Backbone.Events,\n * Radio.Commands, and Radio.Requests.\n *\n */\n\n Radio.Channel = function(channelName) {\n this.channelName = channelName;\n };\n\n _.extend(Radio.Channel.prototype, Backbone.Events, Radio.Commands, Radio.Requests, {\n\n // Remove all handlers from the messaging systems of this channel\n reset: function() {\n this.off();\n this.stopListening();\n this.stopComplying();\n this.stopReplying();\n return this;\n }\n });\n\n /*\n * Top-level API\n * -------------\n * Supplies the 'top-level API' for working with Channels directly\n * from Backbone.Radio.\n *\n */\n\n var channel, args, systems = [Backbone.Events, Radio.Commands, Radio.Requests];\n\n _.each(systems, function(system) {\n _.each(system, function(method, methodName) {\n Radio[methodName] = function(channelName) {\n args = _.rest(arguments);\n channel = this.channel(channelName);\n return channel[methodName].apply(channel, args);\n };\n });\n });\n\n Radio.reset = function(channelName) {\n var channels = !channelName ? this._channels : [this._channels[channelName]];\n _.invoke(channels, 'reset');\n };\n\n var backbone_radio = Radio;\n\n return backbone_radio;\n\n}));\n","// Backbone.Radio v0.9.1\n(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('underscore'), require('backbone')) :\n typeof define === 'function' && define.amd ? define(['underscore', 'backbone'], factory) :\n global.Backbone.Radio = factory(global._, global.Backbone)\n}(this, function (_, Backbone) { 'use strict';\n\n var previousRadio = Backbone.Radio;\n\n var Radio = Backbone.Radio = {};\n\n Radio.VERSION = '0.9.1';\n\n // This allows you to run multiple instances of Radio on the same\n // webapp. After loading the new version, call `noConflict()` to\n // get a reference to it. At the same time the old version will be\n // returned to Backbone.Radio.\n Radio.noConflict = function () {\n Backbone.Radio = previousRadio;\n return this;\n };\n\n // Whether or not we're in DEBUG mode or not. DEBUG mode helps you\n // get around the issues of lack of warnings when events are mis-typed.\n Radio.DEBUG = false;\n\n // Format debug text.\n Radio._debugText = function(warning, eventName, channelName) {\n return warning + (channelName ? ' on the ' + channelName + ' channel' : '') +\n ': \"' + eventName + '\"';\n };\n\n // This is the method that's called when an unregistered event was called.\n // By default, it logs warning to the console. By overriding this you could\n // make it throw an Error, for instance. This would make firing a nonexistent event\n // have the same consequence as firing a nonexistent method on an Object.\n Radio.debugLog = function(warning, eventName, channelName) {\n if (Radio.DEBUG && console && console.warn) {\n console.warn(Radio._debugText(warning, eventName, channelName));\n }\n };\n\n var eventSplitter = /\\s+/;\n\n // An internal method used to handle Radio's method overloading for Requests and\n // Commands. It's borrowed from Backbone.Events. It differs from Backbone's overload\n // API (which is used in Backbone.Events) in that it doesn't support space-separated\n // event names.\n Radio._eventsApi = function(obj, action, name, rest) {\n if (!name) {\n return false;\n }\n\n var results = {};\n\n // Handle event maps.\n if (typeof name === 'object') {\n for (var key in name) {\n var result = obj[action].apply(obj, [key, name[key]].concat(rest));\n eventSplitter.test(key) ? _.extend(results, result) : results[key] = result;\n }\n return results;\n }\n\n // Handle space separated event names.\n if (eventSplitter.test(name)) {\n var names = name.split(eventSplitter);\n for (var i = 0, l = names.length; i < l; i++) {\n results[names[i]] = obj[action].apply(obj, [names[i]].concat(rest));\n }\n return results;\n }\n\n return false;\n };\n\n // An optimized way to execute callbacks.\n Radio._callHandler = function(callback, context, args) {\n var a1 = args[0], a2 = args[1], a3 = args[2];\n switch(args.length) {\n case 0: return callback.call(context);\n case 1: return callback.call(context, a1);\n case 2: return callback.call(context, a1, a2);\n case 3: return callback.call(context, a1, a2, a3);\n default: return callback.apply(context, args);\n }\n };\n\n // A helper used by `off` methods to the handler from the store\n function removeHandler(store, name, callback, context) {\n var event = store[name];\n if (\n (!callback || (callback === event.callback || callback === event.callback._callback)) &&\n (!context || (context === event.context))\n ) {\n delete store[name];\n return true;\n }\n }\n\n function removeHandlers(store, name, callback, context) {\n store || (store = {});\n var names = name ? [name] : _.keys(store);\n var matched = false;\n\n for (var i = 0, length = names.length; i < length; i++) {\n name = names[i];\n\n // If there's no event by this name, log it and continue\n // with the loop\n if (!store[name]) {\n continue;\n }\n\n if (removeHandler(store, name, callback, context)) {\n matched = true;\n }\n }\n\n return matched;\n }\n\n /*\n * tune-in\n * -------\n * Get console logs of a channel's activity\n *\n */\n\n var _logs = {};\n\n // This is to produce an identical function in both tuneIn and tuneOut,\n // so that Backbone.Events unregisters it.\n function _partial(channelName) {\n return _logs[channelName] || (_logs[channelName] = _.partial(Radio.log, channelName));\n }\n\n _.extend(Radio, {\n\n // Log information about the channel and event\n log: function(channelName, eventName) {\n var args = _.rest(arguments, 2);\n console.log('[' + channelName + '] \"' + eventName + '\"', args);\n },\n\n // Logs all events on this channel to the console. It sets an\n // internal value on the channel telling it we're listening,\n // then sets a listener on the Backbone.Events\n tuneIn: function(channelName) {\n var channel = Radio.channel(channelName);\n channel._tunedIn = true;\n channel.on('all', _partial(channelName));\n return this;\n },\n\n // Stop logging all of the activities on this channel to the console\n tuneOut: function(channelName) {\n var channel = Radio.channel(channelName);\n channel._tunedIn = false;\n channel.off('all', _partial(channelName));\n delete _logs[channelName];\n return this;\n }\n });\n\n /*\n * Backbone.Radio.Commands\n * -----------------------\n * A messaging system for sending orders.\n *\n */\n\n Radio.Commands = {\n\n // Issue a command\n command: function(name) {\n var args = _.rest(arguments);\n if (Radio._eventsApi(this, 'command', name, args)) {\n return this;\n }\n var channelName = this.channelName;\n var commands = this._commands;\n\n // Check if we should log the command, and if so, do it\n if (channelName && this._tunedIn) {\n Radio.log.apply(this, [channelName, name].concat(args));\n }\n\n // If the command isn't handled, log it in DEBUG mode and exit\n if (commands && (commands[name] || commands['default'])) {\n var handler = commands[name] || commands['default'];\n args = commands[name] ? args : arguments;\n Radio._callHandler(handler.callback, handler.context, args);\n } else {\n Radio.debugLog('An unhandled command was fired', name, channelName);\n }\n\n return this;\n },\n\n // Register a handler for a command.\n comply: function(name, callback, context) {\n if (Radio._eventsApi(this, 'comply', name, [callback, context])) {\n return this;\n }\n this._commands || (this._commands = {});\n\n if (this._commands[name]) {\n Radio.debugLog('A command was overwritten', name, this.channelName);\n }\n\n this._commands[name] = {\n callback: callback,\n context: context || this\n };\n\n return this;\n },\n\n // Register a handler for a command that happens just once.\n complyOnce: function(name, callback, context) {\n if (Radio._eventsApi(this, 'complyOnce', name, [callback, context])) {\n return this;\n }\n var self = this;\n\n var once = _.once(function() {\n self.stopComplying(name);\n return callback.apply(this, arguments);\n });\n\n return this.comply(name, once, context);\n },\n\n // Remove handler(s)\n stopComplying: function(name, callback, context) {\n if (Radio._eventsApi(this, 'stopComplying', name)) {\n return this;\n }\n\n // Remove everything if there are no arguments passed\n if (!name && !callback && !context) {\n delete this._commands;\n } else if (!removeHandlers(this._commands, name, callback, context)) {\n Radio.debugLog('Attempted to remove the unregistered command', name, this.channelName);\n }\n\n return this;\n }\n };\n\n /*\n * Backbone.Radio.Requests\n * -----------------------\n * A messaging system for requesting data.\n *\n */\n\n function makeCallback(callback) {\n return _.isFunction(callback) ? callback : function () { return callback; };\n }\n\n Radio.Requests = {\n\n // Make a request\n request: function(name) {\n var args = _.rest(arguments);\n var results = Radio._eventsApi(this, 'request', name, args);\n if (results) {\n return results;\n }\n var channelName = this.channelName;\n var requests = this._requests;\n\n // Check if we should log the request, and if so, do it\n if (channelName && this._tunedIn) {\n Radio.log.apply(this, [channelName, name].concat(args));\n }\n\n // If the request isn't handled, log it in DEBUG mode and exit\n if (requests && (requests[name] || requests['default'])) {\n var handler = requests[name] || requests['default'];\n args = requests[name] ? args : arguments;\n return Radio._callHandler(handler.callback, handler.context, args);\n } else {\n Radio.debugLog('An unhandled request was fired', name, channelName);\n }\n },\n\n // Set up a handler for a request\n reply: function(name, callback, context) {\n if (Radio._eventsApi(this, 'reply', name, [callback, context])) {\n return this;\n }\n\n this._requests || (this._requests = {});\n\n if (this._requests[name]) {\n Radio.debugLog('A request was overwritten', name, this.channelName);\n }\n\n this._requests[name] = {\n callback: makeCallback(callback),\n context: context || this\n };\n\n return this;\n },\n\n // Set up a handler that can only be requested once\n replyOnce: function(name, callback, context) {\n if (Radio._eventsApi(this, 'replyOnce', name, [callback, context])) {\n return this;\n }\n\n var self = this;\n\n var once = _.once(function() {\n self.stopReplying(name);\n return makeCallback(callback).apply(this, arguments);\n });\n\n return this.reply(name, once, context);\n },\n\n // Remove handler(s)\n stopReplying: function(name, callback, context) {\n if (Radio._eventsApi(this, 'stopReplying', name)) {\n return this;\n }\n\n // Remove everything if there are no arguments passed\n if (!name && !callback && !context) {\n delete this._requests;\n } else if (!removeHandlers(this._requests, name, callback, context)) {\n Radio.debugLog('Attempted to remove the unregistered request', name, this.channelName);\n }\n\n return this;\n }\n };\n\n /*\n * Backbone.Radio.channel\n * ----------------------\n * Get a reference to a channel by name.\n *\n */\n\n Radio._channels = {};\n\n Radio.channel = function(channelName) {\n if (!channelName) {\n throw new Error('You must provide a name for the channel.');\n }\n\n if (Radio._channels[channelName]) {\n return Radio._channels[channelName];\n } else {\n return (Radio._channels[channelName] = new Radio.Channel(channelName));\n }\n };\n\n /*\n * Backbone.Radio.Channel\n * ----------------------\n * A Channel is an object that extends from Backbone.Events,\n * Radio.Commands, and Radio.Requests.\n *\n */\n\n Radio.Channel = function(channelName) {\n this.channelName = channelName;\n };\n\n _.extend(Radio.Channel.prototype, Backbone.Events, Radio.Commands, Radio.Requests, {\n\n // Remove all handlers from the messaging systems of this channel\n reset: function() {\n this.off();\n this.stopListening();\n this.stopComplying();\n this.stopReplying();\n return this;\n }\n });\n\n /*\n * Top-level API\n * -------------\n * Supplies the 'top-level API' for working with Channels directly\n * from Backbone.Radio.\n *\n */\n\n var channel, args, systems = [Backbone.Events, Radio.Commands, Radio.Requests];\n\n _.each(systems, function(system) {\n _.each(system, function(method, methodName) {\n Radio[methodName] = function(channelName) {\n args = _.rest(arguments);\n channel = this.channel(channelName);\n return channel[methodName].apply(channel, args);\n };\n });\n });\n\n Radio.reset = function(channelName) {\n var channels = !channelName ? this._channels : [this._channels[channelName]];\n _.invoke(channels, 'reset');\n };\n\n var backbone_radio = Radio;\n\n return backbone_radio;\n\n}));\n"]} \ No newline at end of file diff --git a/package.json b/package.json index eb6a3fb..8351cbe 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "backbone.radio", "description": "Messaging patterns for Backbone applications.", "homepage": "https://github.com/marionettejs/backbone.radio", - "version": "0.9.0", + "version": "0.9.1", "main": "build/backbone.radio.js", "keywords": [ "backbone",