Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Created Publisher

  • Loading branch information...
commit 4bb76071cec60e6a53468a8c5f9471de33e33596 1 parent 0e2fa95
@rgr-myrg authored
Showing with 34 additions and 0 deletions.
  1. +34 −0 src/publisher.js
View
34 src/publisher.js
@@ -0,0 +1,34 @@
+/**
+ * Copyright (c) 2011 Roger Myrg http://devshop.me/
+ * Released under the MIT license:
+ * https://github.com/rgr-myrg/DevShop-JS/raw/master/MIT-LICENSE
+ */
+(function(DevShop){
+ DevShop.Publisher=function(){
+ var subscribers=[];
+ var events={};
+ return {
+ registerEvents: function(eventList){
+ if(typeof eventList === 'object'){
+ events = eventList;
+ }
+ },
+ registerSubscriber: function(subscriber){
+ if(typeof subscriber.onRegister === 'function'){
+ var listeners = subscriber.onRegister();
+ for(var i in listeners){
+ if(listeners.hasOwnProperty(i) && typeof events[i] === 'object'){
+ events[i].addListener(listeners[i]);
+ }
+ }
+ subscriber.onRegister=function(){};
+ }
+ },
+ notify: function(event, data){
+ if(typeof event.dispatch === 'function'){
+ event.dispatch(data);
+ }
+ }
+ };
+ };
+})(DevShop);
Please sign in to comment.
Something went wrong with that request. Please try again.