Permalink
Browse files

Created Publisher

  • Loading branch information...
1 parent 0e2fa95 commit 4bb76071cec60e6a53468a8c5f9471de33e33596 @rgr-myrg committed Dec 23, 2011
Showing with 34 additions and 0 deletions.
  1. +34 −0 src/publisher.js
View
@@ -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);

0 comments on commit 4bb7607

Please sign in to comment.