Editing A Comparison of JS Publish/Subscribe Approaches This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) # A Comparison of JS Publish/Subscribe Approaches More info: [publish/subscribe](http://en.wikipedia.org/wiki/Publish/subscribe) on Wikipedia. *Compared:* * [jQuery custom events](http://api.jquery.com/category/events/) * [PubSubJS](http://roderick.dk/blog/2010/10/12/introducing-pubsubjs-a-library-for-doing-publish-subscribe-in-javascript/) * [jQuery PubSub plugin](https://github.com/kuwabarahiroshi/bloody-jquery-plugins/blob/master/pubsub.js) * [Pure JS PubSub](https://github.com/phiggins42/bloody-jquery-plugins/blob/55e41df9bf08f42378bb08b93efcb28555b61aeb/pubsub.js) * [Amplify Pub/Sub](http://amplifyjs.com/) * [Spine Events](http://spinejs.com/) * [Ply](https://github.com/richardscarrott/ply/) * [Hyraki](https://raw.github.com/jkroso/Observer/master/lib/Observer.js) * [Station](https://raw.github.com/jkroso/Station/master/distBuild/Station.js) Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"> </script> <script src="https://raw.github.com/mroderick/PubSubJS/master/src/pubsub.js" type="text/javascript"> </script> <script src="https://raw.github.com/kuwabarahiroshi/bloody-jquery-plugins/master/pubsub.js" type="text/javascript"> </script> <script src="https://raw.github.com/phiggins42/bloody-jquery-plugins/55e41df9bf08f42378bb08b93efcb28555b61aeb/pubsub.js" type="text/javascript"> </script> <script src="https://raw.github.com/gist/1695338/736bcf94f9226d975fce3ad4f2bc08ccbf176bad/pubsub.js" type="text/javascript"> </script> <script src="https://raw.github.com/appendto/amplify/master/core/amplify.core.js" type="text/javascript"> </script> <script src="https://raw.github.com/maccman/spine/master/lib/spine.js" type="text/javascript"> </script> <script src="https://raw.github.com/richardscarrott/ply/master/src/core.js" type="text/javascript"> </script> <script src="https://raw.github.com/jrburke/requirejs/master/require.js" type="text/javascript"> </script> <script type="text/javascript"> window.callback = function () {}; window.payload = { somekey: 'some value' }; var Observer = jQuery({}); jQuery(function() { require(["https://raw.github.com/jkroso/Observer/master/dist/Observer.min.js"], function(Hyraki){ window.hyraki = new Hyraki() for (var i = 0; i < 10; i++) { Observer.on('my-event-' + i, callback); PubSub.subscribe('my-event-' + i, callback); jQuery.subscribe('my-event-' + i, callback); Events.subscribe('my-event-' + i, callback); App.subscribe('my-event-' + i, callback); amplify.subscribe('my-event-' + i, callback); Spine.bind('my-event-' + i, callback); Ply.core.listen('my-event-' + i, callback); hyraki.on('my-event-' + i, callback); } }) }); </script> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code Observer.trigger('my-event-9', payload); Test 2 Title Async (check if this is an asynchronous test) Code PubSub.publish('my-event-9', payload); Test 3 Title Async (check if this is an asynchronous test) Code $.publish('my-event-9', [payload]); Test 4 Title Async (check if this is an asynchronous test) Code Events.publish('my-event-9', [payload]); Test 5 Title Async (check if this is an asynchronous test) Code amplify.publish('my-event-9', payload); Test 6 Title Async (check if this is an asynchronous test) Code Spine.trigger('my-event-9', payload); Test 7 Title Async (check if this is an asynchronous test) Code Ply.core.notify('my-event-9', window, payload); Test 8 Title Async (check if this is an asynchronous test) Code hyraki.publish('my-event-9', payload); Test 9 Title Async (check if this is an asynchronous test) Code hyraki.run('my-event-9', payload);