Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added Publisher/Subscriber example

  • Loading branch information...
commit a2109e9824c90575d3822d91433a6900aa3e66b7 1 parent 16e520e
@rgr-myrg authored
View
7 build.sh
@@ -15,6 +15,11 @@ do :
;;
esac
case "$i" in
+ "publisher")
+ files="--js src/core.js --js src/eventsignal.js --js src/publisher.js"
+ ;;
+ esac
+ case "$i" in
"mvc")
files="--js src/core.js --js src/singletonfactory.js --js src/observable.js --js src/observer.js --js src/mvc.js"
;;
@@ -31,7 +36,7 @@ do :
esac
case "$i" in
"full")
- files="--js src/core.js --js src/singletonfactory.js --js src/observable.js --js src/observer.js --js src/eventsignal.js --js src/mvc.js"
+ files="--js src/core.js --js src/singletonfactory.js --js src/observable.js --js src/observer.js --js src/eventsignal.js --js src/mvc.js --js src/publisher.js"
;;
esac
artifact="build/devshop-"$i".js"
View
10 build/devshop-full.js
@@ -3,8 +3,8 @@
* Released under the MIT license:
* https://github.com/rgr-myrg/DevShop-JS/raw/master/MIT-LICENSE
*/
-(function(b){b.DevShop=typeof b.DevShop==="object"?b.DevShop:{}})(window);(function(b){b.SingletonFactory=function(b){var c=function(a){if(typeof a==="function")try{return new a}catch(d){}else if(typeof a==="object")return a},e=c(b.implement),a=c(b.extend),c=c(b.instance),d;for(d in a)a.hasOwnProperty(d)&&(c[d]||(c[d]=a[d]));for(d in e)if(e.hasOwnProperty(d)&&!c[d])throw b.instance+" must implement '"+d+"' "+typeof e[d];if(typeof c.initialize==="function")try{c.initialize()}catch(h){}return c}})(DevShop);(function(b){b.Observable=function(f){return b.SingletonFactory({extend:function(){this.observers=[];this.addObserver=function(c){if((typeof c==="function"||typeof c==="object")&&typeof c.notify==="function")if(this.observers.push(c),typeof c.onRegister==="function")try{c.onRegister()}catch(b){}};this.notifyObservers=function(c){for(var b=this.observers.length,a=0;a<b;a++)try{this.observers[a].notify(c,this)}catch(d){}}},instance:f})}})(DevShop);(function(b){b.Observer=function(f){return b.SingletonFactory({extend:function(){this.onRegister=function(){};this.notify=function(c,b){this.observable=b;if(typeof this[c]==="function")try{this[c]()}catch(a){}}},instance:f})}})(DevShop);(function(b){b.EventSignal=function(){var b=[];this.addListener=function(c){typeof c==="function"&&b.push(c)};this.removeListener=function(c){for(var e=b.length,a=0;a<e;a++)b[a]===c&&b.splice(a)};this.dispatch=function(){for(var c=b.length,e=0;e<c;e++)try{b[e].apply(this,arguments)}catch(a){}}}})(DevShop);(function(b){b.IProxy={NAME:""};b.IMediator={NAME:"",listNotificationInterests:function(){},handleNotification:function(){}};b.ICommand={execute:function(){}};b.Proxy=function(){var b={};this.facade=null;this.setData=function(c){b=c};this.getData=function(){return b};this.onRegister=function(){};this.onRemove=function(){}};b.Mediator=b.Observer(function(){this.facade=null;this.onRegister=function(){};this.onRemove=function(){}});b.Facade=function(){var f=new function(){var a={};this.facade={};this.registerProxy=
-function(d){d.facade=this.facade;a[d.NAME]||(a[d.NAME]=d);if(typeof d.onRegister==="function")try{d.onRegister()}catch(b){}};this.retrieveProxy=function(d){return a[d]?a[d]:null};this.removeProxy=function(d){if(typeof a[d].onRemove==="function")try{a[d].onRemove()}catch(b){}a[d]=null}},c=new b.Observable(function(){var a={};this.facade={};this.notification={};this.registerMediator=function(d){d.facade=this.facade;a[d.NAME]||(a[d.NAME]=d,this.addObserver(d))};this.retrieveMediator=function(d){return a[d]?
-a[d]:null};this.removeMediator=function(d){if(typeof a[d].onRemove==="function")try{a[d].onRemove()}catch(b){}a[d]=null};this.notifyObservers=function(a){for(var b=this.observers.length,c=0;c<b;c++)try{for(var e=this.observers[c].listNotificationInterests(),f=!1,g=0;l=e.length,g<l;g++)if(e[g]==this.notification.name){f=!0;break}if(f)this.observers[c].notification=this.notification,this.observers[c].notify(a,this)}catch(i){}};this.sendNotification=function(a){this.notification=a;this.notifyObservers("handleNotification")}}),
-e=new b.Observer(function(){var a={},b=[];this.facade={};this.NAME="DevShop.Controller";this.registerCommand=function(c,e){e.facade=this.facade;a[c]||(a[c]=e,b.push(c))};this.listNotificationInterests=function(){return b};this.handleNotification=function(){var b=this.notification;if(typeof a[b.name]==="object"&&typeof a[b.name].execute==="function")try{a[b.name].execute(b)}catch(c){}}});this.CMD_STARTUP="CMD_STARTUP";this.registerProxy=function(a){f.registerProxy(a)};this.registerMediator=function(a){c.registerMediator(a)};
-this.registerCommand=function(a,b){e.registerCommand(a,b)};this.retrieveProxy=function(a){return f.retrieveProxy(a)};this.retrieveMediator=function(a){return c.retrieveMediator(a)};this.removeProxy=function(a){f.removeProxy(a)};this.removeMediator=function(a){c.removeMediator(a)};this.sendNotification=function(a,b,e){c.sendNotification({name:a,body:b,type:e})};this.initializeFacade=function(){f.facade=this;c.facade=this;e.facade=this;this.registerMediator(e)}}})(DevShop);
+(function(b){b.DevShop=typeof b.DevShop==="object"?b.DevShop:{}})(window);(function(b){b.SingletonFactory=function(e){var c=function(a){if(typeof a==="function")try{return new a}catch(d){}else if(typeof a==="object")return a},b=c(e.implement),a=c(e.extend),c=c(e.instance),d;for(d in a)a.hasOwnProperty(d)&&(c[d]||(c[d]=a[d]));for(d in b)if(b.hasOwnProperty(d)&&!c[d])throw e.instance+" must implement '"+d+"' "+typeof b[d];if(typeof c.initialize==="function")try{c.initialize()}catch(h){}return c}})(DevShop);(function(b){b.Observable=function(e){return b.SingletonFactory({extend:function(){this.observers=[];this.addObserver=function(c){if((typeof c==="function"||typeof c==="object")&&typeof c.notify==="function")if(this.observers.push(c),typeof c.onRegister==="function")try{c.onRegister()}catch(b){}};this.notifyObservers=function(c){for(var b=this.observers.length,a=0;a<b;a++)try{this.observers[a].notify(c,this)}catch(d){}}},instance:e})}})(DevShop);(function(b){b.Observer=function(e){return b.SingletonFactory({extend:function(){this.onRegister=function(){};this.notify=function(c,b){this.observable=b;if(typeof this[c]==="function")try{this[c]()}catch(a){}}},instance:e})}})(DevShop);(function(b){b.EventSignal=function(){var b=[];this.addListener=function(c){typeof c==="function"&&b.push(c)};this.removeListener=function(c){for(var f=b.length,a=0;a<f;a++)b[a]===c&&b.splice(a)};this.dispatch=function(){for(var c=b.length,f=0;f<c;f++)try{b[f].apply(this,arguments)}catch(a){}}}})(DevShop);(function(b){b.IProxy={NAME:""};b.IMediator={NAME:"",listNotificationInterests:function(){},handleNotification:function(){}};b.ICommand={execute:function(){}};b.Proxy=function(){var b={};this.facade=null;this.setData=function(c){b=c};this.getData=function(){return b};this.onRegister=function(){};this.onRemove=function(){}};b.Mediator=b.Observer(function(){this.facade=null;this.onRegister=function(){};this.onRemove=function(){}});b.Facade=function(){var e=new function(){var a={};this.facade={};this.registerProxy=
+function(d){d.facade=this.facade;a[d.NAME]||(a[d.NAME]=d);if(typeof d.onRegister==="function")try{d.onRegister()}catch(c){}};this.retrieveProxy=function(d){return a[d]?a[d]:null};this.removeProxy=function(d){if(typeof a[d].onRemove==="function")try{a[d].onRemove()}catch(c){}a[d]=null}},c=new b.Observable(function(){var a={};this.facade={};this.notification={};this.registerMediator=function(d){d.facade=this.facade;a[d.NAME]||(a[d.NAME]=d,this.addObserver(d))};this.retrieveMediator=function(d){return a[d]?
+a[d]:null};this.removeMediator=function(d){if(typeof a[d].onRemove==="function")try{a[d].onRemove()}catch(c){}a[d]=null};this.notifyObservers=function(a){for(var c=this.observers.length,b=0;b<c;b++)try{for(var e=this.observers[b].listNotificationInterests(),f=!1,g=0;l=e.length,g<l;g++)if(e[g]==this.notification.name){f=!0;break}if(f)this.observers[b].notification=this.notification,this.observers[b].notify(a,this)}catch(i){}};this.sendNotification=function(a){this.notification=a;this.notifyObservers("handleNotification")}}),
+f=new b.Observer(function(){var a={},c=[];this.facade={};this.NAME="DevShop.Controller";this.registerCommand=function(b,e){e.facade=this.facade;a[b]||(a[b]=e,c.push(b))};this.listNotificationInterests=function(){return c};this.handleNotification=function(){var c=this.notification;if(typeof a[c.name]==="object"&&typeof a[c.name].execute==="function")try{a[c.name].execute(c)}catch(b){}}});this.CMD_STARTUP="CMD_STARTUP";this.registerProxy=function(a){e.registerProxy(a)};this.registerMediator=function(a){c.registerMediator(a)};
+this.registerCommand=function(a,c){f.registerCommand(a,c)};this.retrieveProxy=function(a){return e.retrieveProxy(a)};this.retrieveMediator=function(a){return c.retrieveMediator(a)};this.removeProxy=function(a){e.removeProxy(a)};this.removeMediator=function(a){c.removeMediator(a)};this.sendNotification=function(a,b,e){c.sendNotification({name:a,body:b,type:e})};this.initializeFacade=function(){e.facade=this;c.facade=this;f.facade=this;this.registerMediator(f)}}})(DevShop);(function(b){b.Publisher=function(){var b={};return{registerEvents:function(c){typeof c==="object"&&(b=c)},registerSubscriber:function(c){if(typeof c.onRegister==="function"){var f=c.onRegister(),a;for(a in f)f.hasOwnProperty(a)&&typeof b[a]==="object"&&b[a].addListener(f[a]);c.onRegister=function(){}}},notify:function(c,b){typeof c.dispatch==="function"&&c.dispatch(b)}}}})(DevShop);
View
10 examples/devshop-full.js
@@ -3,8 +3,8 @@
* Released under the MIT license:
* https://github.com/rgr-myrg/DevShop-JS/raw/master/MIT-LICENSE
*/
-(function(b){b.DevShop=typeof b.DevShop==="object"?b.DevShop:{}})(window);(function(b){b.SingletonFactory=function(b){var c=function(a){if(typeof a==="function")try{return new a}catch(d){}else if(typeof a==="object")return a},e=c(b.implement),a=c(b.extend),c=c(b.instance),d;for(d in a)a.hasOwnProperty(d)&&(c[d]||(c[d]=a[d]));for(d in e)if(e.hasOwnProperty(d)&&!c[d])throw b.instance+" must implement '"+d+"' "+typeof e[d];if(typeof c.initialize==="function")try{c.initialize()}catch(h){}return c}})(DevShop);(function(b){b.Observable=function(f){return b.SingletonFactory({extend:function(){this.observers=[];this.addObserver=function(c){if((typeof c==="function"||typeof c==="object")&&typeof c.notify==="function")if(this.observers.push(c),typeof c.onRegister==="function")try{c.onRegister()}catch(b){}};this.notifyObservers=function(c){for(var b=this.observers.length,a=0;a<b;a++)try{this.observers[a].notify(c,this)}catch(d){}}},instance:f})}})(DevShop);(function(b){b.Observer=function(f){return b.SingletonFactory({extend:function(){this.onRegister=function(){};this.notify=function(c,b){this.observable=b;if(typeof this[c]==="function")try{this[c]()}catch(a){}}},instance:f})}})(DevShop);(function(b){b.EventSignal=function(){var b=[];this.addListener=function(c){typeof c==="function"&&b.push(c)};this.removeListener=function(c){for(var e=b.length,a=0;a<e;a++)b[a]===c&&b.splice(a)};this.dispatch=function(){for(var c=b.length,e=0;e<c;e++)try{b[e].apply(this,arguments)}catch(a){}}}})(DevShop);(function(b){b.IProxy={NAME:""};b.IMediator={NAME:"",listNotificationInterests:function(){},handleNotification:function(){}};b.ICommand={execute:function(){}};b.Proxy=function(){var b={};this.facade=null;this.setData=function(c){b=c};this.getData=function(){return b};this.onRegister=function(){};this.onRemove=function(){}};b.Mediator=b.Observer(function(){this.facade=null;this.onRegister=function(){};this.onRemove=function(){}});b.Facade=function(){var f=new function(){var a={};this.facade={};this.registerProxy=
-function(d){d.facade=this.facade;a[d.NAME]||(a[d.NAME]=d);if(typeof d.onRegister==="function")try{d.onRegister()}catch(b){}};this.retrieveProxy=function(d){return a[d]?a[d]:null};this.removeProxy=function(d){if(typeof a[d].onRemove==="function")try{a[d].onRemove()}catch(b){}a[d]=null}},c=new b.Observable(function(){var a={};this.facade={};this.notification={};this.registerMediator=function(d){d.facade=this.facade;a[d.NAME]||(a[d.NAME]=d,this.addObserver(d))};this.retrieveMediator=function(d){return a[d]?
-a[d]:null};this.removeMediator=function(d){if(typeof a[d].onRemove==="function")try{a[d].onRemove()}catch(b){}a[d]=null};this.notifyObservers=function(a){for(var b=this.observers.length,c=0;c<b;c++)try{for(var e=this.observers[c].listNotificationInterests(),f=!1,g=0;l=e.length,g<l;g++)if(e[g]==this.notification.name){f=!0;break}if(f)this.observers[c].notification=this.notification,this.observers[c].notify(a,this)}catch(i){}};this.sendNotification=function(a){this.notification=a;this.notifyObservers("handleNotification")}}),
-e=new b.Observer(function(){var a={},b=[];this.facade={};this.NAME="DevShop.Controller";this.registerCommand=function(c,e){e.facade=this.facade;a[c]||(a[c]=e,b.push(c))};this.listNotificationInterests=function(){return b};this.handleNotification=function(){var b=this.notification;if(typeof a[b.name]==="object"&&typeof a[b.name].execute==="function")try{a[b.name].execute(b)}catch(c){}}});this.CMD_STARTUP="CMD_STARTUP";this.registerProxy=function(a){f.registerProxy(a)};this.registerMediator=function(a){c.registerMediator(a)};
-this.registerCommand=function(a,b){e.registerCommand(a,b)};this.retrieveProxy=function(a){return f.retrieveProxy(a)};this.retrieveMediator=function(a){return c.retrieveMediator(a)};this.removeProxy=function(a){f.removeProxy(a)};this.removeMediator=function(a){c.removeMediator(a)};this.sendNotification=function(a,b,e){c.sendNotification({name:a,body:b,type:e})};this.initializeFacade=function(){f.facade=this;c.facade=this;e.facade=this;this.registerMediator(e)}}})(DevShop);
+(function(b){b.DevShop=typeof b.DevShop==="object"?b.DevShop:{}})(window);(function(b){b.SingletonFactory=function(e){var c=function(a){if(typeof a==="function")try{return new a}catch(d){}else if(typeof a==="object")return a},b=c(e.implement),a=c(e.extend),c=c(e.instance),d;for(d in a)a.hasOwnProperty(d)&&(c[d]||(c[d]=a[d]));for(d in b)if(b.hasOwnProperty(d)&&!c[d])throw e.instance+" must implement '"+d+"' "+typeof b[d];if(typeof c.initialize==="function")try{c.initialize()}catch(h){}return c}})(DevShop);(function(b){b.Observable=function(e){return b.SingletonFactory({extend:function(){this.observers=[];this.addObserver=function(c){if((typeof c==="function"||typeof c==="object")&&typeof c.notify==="function")if(this.observers.push(c),typeof c.onRegister==="function")try{c.onRegister()}catch(b){}};this.notifyObservers=function(c){for(var b=this.observers.length,a=0;a<b;a++)try{this.observers[a].notify(c,this)}catch(d){}}},instance:e})}})(DevShop);(function(b){b.Observer=function(e){return b.SingletonFactory({extend:function(){this.onRegister=function(){};this.notify=function(c,b){this.observable=b;if(typeof this[c]==="function")try{this[c]()}catch(a){}}},instance:e})}})(DevShop);(function(b){b.EventSignal=function(){var b=[];this.addListener=function(c){typeof c==="function"&&b.push(c)};this.removeListener=function(c){for(var f=b.length,a=0;a<f;a++)b[a]===c&&b.splice(a)};this.dispatch=function(){for(var c=b.length,f=0;f<c;f++)try{b[f].apply(this,arguments)}catch(a){}}}})(DevShop);(function(b){b.IProxy={NAME:""};b.IMediator={NAME:"",listNotificationInterests:function(){},handleNotification:function(){}};b.ICommand={execute:function(){}};b.Proxy=function(){var b={};this.facade=null;this.setData=function(c){b=c};this.getData=function(){return b};this.onRegister=function(){};this.onRemove=function(){}};b.Mediator=b.Observer(function(){this.facade=null;this.onRegister=function(){};this.onRemove=function(){}});b.Facade=function(){var e=new function(){var a={};this.facade={};this.registerProxy=
+function(d){d.facade=this.facade;a[d.NAME]||(a[d.NAME]=d);if(typeof d.onRegister==="function")try{d.onRegister()}catch(c){}};this.retrieveProxy=function(d){return a[d]?a[d]:null};this.removeProxy=function(d){if(typeof a[d].onRemove==="function")try{a[d].onRemove()}catch(c){}a[d]=null}},c=new b.Observable(function(){var a={};this.facade={};this.notification={};this.registerMediator=function(d){d.facade=this.facade;a[d.NAME]||(a[d.NAME]=d,this.addObserver(d))};this.retrieveMediator=function(d){return a[d]?
+a[d]:null};this.removeMediator=function(d){if(typeof a[d].onRemove==="function")try{a[d].onRemove()}catch(c){}a[d]=null};this.notifyObservers=function(a){for(var c=this.observers.length,b=0;b<c;b++)try{for(var e=this.observers[b].listNotificationInterests(),f=!1,g=0;l=e.length,g<l;g++)if(e[g]==this.notification.name){f=!0;break}if(f)this.observers[b].notification=this.notification,this.observers[b].notify(a,this)}catch(i){}};this.sendNotification=function(a){this.notification=a;this.notifyObservers("handleNotification")}}),
+f=new b.Observer(function(){var a={},c=[];this.facade={};this.NAME="DevShop.Controller";this.registerCommand=function(b,e){e.facade=this.facade;a[b]||(a[b]=e,c.push(b))};this.listNotificationInterests=function(){return c};this.handleNotification=function(){var c=this.notification;if(typeof a[c.name]==="object"&&typeof a[c.name].execute==="function")try{a[c.name].execute(c)}catch(b){}}});this.CMD_STARTUP="CMD_STARTUP";this.registerProxy=function(a){e.registerProxy(a)};this.registerMediator=function(a){c.registerMediator(a)};
+this.registerCommand=function(a,c){f.registerCommand(a,c)};this.retrieveProxy=function(a){return e.retrieveProxy(a)};this.retrieveMediator=function(a){return c.retrieveMediator(a)};this.removeProxy=function(a){e.removeProxy(a)};this.removeMediator=function(a){c.removeMediator(a)};this.sendNotification=function(a,b,e){c.sendNotification({name:a,body:b,type:e})};this.initializeFacade=function(){e.facade=this;c.facade=this;f.facade=this;this.registerMediator(f)}}})(DevShop);(function(b){b.Publisher=function(){var b={};return{registerEvents:function(c){typeof c==="object"&&(b=c)},registerSubscriber:function(c){if(typeof c.onRegister==="function"){var f=c.onRegister(),a;for(a in f)f.hasOwnProperty(a)&&typeof b[a]==="object"&&b[a].addListener(f[a]);c.onRegister=function(){}}},notify:function(c,b){typeof c.dispatch==="function"&&c.dispatch(b)}}}})(DevShop);
View
81 examples/pubsub.html
@@ -0,0 +1,81 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html xmlns='http://www.w3.org/1999/xhtml' lang='en' xml:lang='en:us'>
+ <head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
+ <title>DevShop.Me :: Event Signal</title>
+ <style>
+ </style>
+ <script type="text/javascript" src="devshop-full.js"></script>
+ <script type="text/javascript">
+ var Echo={
+ onRegister: function(){
+ console.log('onRegister');
+ return {
+ ON_KEYUP: this.onKeyUp
+ };
+ },
+ onKeyUp: function(msg){
+ document.getElementById('echo').innerHTML=msg;
+ }
+ };
+ var Mirror={
+ onRegister: function(){
+ return {
+ ON_KEYUP: this.onKeyUp
+ };
+ },
+ onKeyUp:function(msg){
+ var arr=msg.split('');
+ var msg='';
+ if(arr.length>0)
+ for(var x=arr.length-1;x>=0;x--)
+ msg+=arr[x];
+ document.getElementById('mirror').innerHTML=msg;
+ }
+ };
+ var Vertical={
+ onRegister: function(){
+ return {
+ ON_KEYUP: this.onKeyUp
+ };
+ },
+ onKeyUp:function(msg){
+ var arr=msg.split('');
+ var msg=arr.join('<br>');
+ document.getElementById('vertical').innerHTML=msg;
+ }
+ };
+ var Events={
+ ON_KEYUP: new DevShop.EventSignal
+ };
+ var UI=new DevShop.Publisher();
+ UI.registerEvents(Events);
+ UI.registerSubscriber(Echo);
+ UI.registerSubscriber(Mirror);
+ UI.registerSubscriber(Vertical);
+ UI.onKeyUp=function(){
+ var data = document.getElementById('box').value;
+ this.notify(Events.ON_KEYUP, data);
+ };
+ </script>
+ </head>
+ <body>
+ <form>
+ <table>
+ <tr>
+ <td>Type in this box:</td>
+ <td><input onkeyup="UI.onKeyUp()" type="text" id="box" name="box" value="" size="50"/></td>
+ </tr>
+ <tr>
+ <td>Echo:</td><td><div id="echo"></div></td>
+ </tr>
+ <tr>
+ <td>Mirror:</td><td><div id="mirror"></div></td>
+ </tr>
+ <tr>
+ <td valign="top">Vertical:</td><td valign="top"><div id="vertical"></div></td>
+ </tr>
+ </table>
+ </form>
+ </body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.