Created
January 17, 2012 23:11
-
-
Save tal/1629682 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/main/webapp/WEB-INF/public/javascripts/gilt/notify.js b/src/main/webapp/WEB-INF/public/javascripts/gilt/notify.js | |
| index 604fba9..747b7fb 100644 | |
| --- a/src/main/webapp/WEB-INF/public/javascripts/gilt/notify.js | |
| +++ b/src/main/webapp/WEB-INF/public/javascripts/gilt/notify.js | |
| @@ -44,6 +44,7 @@ Gilt.Notify = Gilt.Notify || (function () { | |
| subscribeMany, | |
| unsubscribe, | |
| unsubscribeMany, | |
| + NAMESPACE_SPLIT = '.', | |
| log = Gilt.Util.logger("notify", "Notify"); | |
| /** | |
| @@ -81,6 +82,33 @@ Gilt.Notify = Gilt.Notify || (function () { | |
| }; | |
| /** | |
| + * Publishes an event on given namespaced channels | |
| + * eg: | |
| + * nsPublish('foo.bar.baz',...) | |
| + * will trigger the events: foo, foo.bar, and foo.bar.baz | |
| + * @method nsPublish | |
| + * @public as nsPublish | |
| + * @param {String} channel A channel on which to publish | |
| + * @param {Array} args An array of arguments to be passed to the subscribers, or [] | |
| + * @param {Object} scope Optional scope in which to execute the subscribers (defaults to window) | |
| + */ | |
| + function nsPublish(channelList, args, scope) { | |
| + var namespaces, channels, newChannel, previousChannel, i; | |
| + namespaces = channelList.split(NAMESPACE_SPLIT); | |
| + | |
| + for (i = 0; i < namespaces.length; i += 1) { | |
| + previousChannel = newChannel; | |
| + newChannel = ''; | |
| + | |
| + if (previousChannel) newChannel += previousChannel + NAMESPACE_SPLIT; | |
| + | |
| + newChannel += namespaces[i]; | |
| + | |
| + publish(newChannel, args, scope); | |
| + } | |
| + } | |
| + | |
| + /** | |
| * Publishes an event on given channels | |
| * @method publishMany | |
| * @public as publishMany | |
| @@ -160,6 +188,7 @@ Gilt.Notify = Gilt.Notify || (function () { | |
| return { | |
| publish : publish, | |
| + nsPublish : nsPublish, | |
| publishMany : publishMany, | |
| subscribe : subscribe, | |
| subscribeMany : subscribeMany, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment