Skip to content

Commit

Permalink
Modified Example
Browse files Browse the repository at this point in the history
  • Loading branch information
rgr-myrg committed May 8, 2011
1 parent 7d5d82c commit d1edc45
Showing 1 changed file with 40 additions and 63 deletions.
103 changes: 40 additions & 63 deletions examples/mvc.html
Expand Up @@ -7,99 +7,76 @@
</style>
<script type="text/javascript" src="devshop.js"></script>
<script type="text/javascript">
var UIMediator=DevShop.SingletonFactory({
extend : DevShop.Mediator,
implement : DevShop.MediatorInterface,
var Echo={
onKeyUp:function(msg){
document.getElementById('echo').innerHTML=msg;
}
};
var Mirror={
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 DataProxy=DevShop.SingletonFactory({
extend : DevShop.Proxy,
implement : DevShop.ProxyInterface,
instance : {
NAME:"UIMediator",
listNotificationInterests:function(){
return [this.facade.ON_KEYUP];
},
handleNotification:function(){
switch(this.notification.name){
case this.facade.ON_KEYUP:
this.facade.retrieveProxy(DataProxy.NAME).setData(this.notification.body);
break;
default:
break;
}
NAME:"DataProxy"
}
});
var StartUpCmd=DevShop.SingletonFactory({
implement : DevShop.CommandInterface,onRegister:function(){alert('y');},
instance : {
execute:function(notification){console.log(notification.name);
this.facade.registerProxy(DataProxy);
this.facade.registerMediator(UIMediator);
}
}
});
var EchoMediator=DevShop.SingletonFactory({
extend : DevShop.Mediator,
implement : DevShop.MediatorInterface,
var KeyUpCmd=DevShop.SingletonFactory({
implement : DevShop.CommandInterface,
instance : {
NAME:"EchoMediator",
listNotificationInterests:function(){
return [this.facade.ON_KEYUP];
},
handleNotification:function(){
switch(this.notification.name){
case this.facade.ON_KEYUP:
this.onKeyUp();
break;
default:
break;
}
},
onKeyUp:function(){
document.getElementById('echo').innerHTML=this.facade.retrieveProxy(DataProxy.NAME).getData();
execute:function(notification){console.log(notification.name);
var msg=this.facade.retrieveProxy(DataProxy.NAME).getData();
Echo.onKeyUp(msg);
Mirror.onKeyUp(msg);
}
}
});
var MirrorMediator=DevShop.SingletonFactory({
var UIMediator=DevShop.SingletonFactory({
extend : DevShop.Mediator,
implement : DevShop.MediatorInterface,
instance : {
NAME:"MirrorMediator",
NAME:"UIMediator",
listNotificationInterests:function(){
return [this.facade.ON_KEYUP];
},
handleNotification:function(){
switch(this.notification.name){
case this.facade.ON_KEYUP:
this.onKeyUp();
this.facade.retrieveProxy(DataProxy.NAME).setData(this.notification.body);
this.facade.sendNotification(this.facade.CMD_KEYUP);
break;
default:
break;
}
},
onKeyUp:function(){
var arr=this.facade.retrieveProxy(DataProxy.NAME).getData().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 DataProxy=DevShop.SingletonFactory({
extend : DevShop.Proxy,
implement : DevShop.ProxyInterface,
instance : {
NAME:"DataProxy"
}
});
var StartUpCmd=DevShop.SingletonFactory({
implement : DevShop.CommandInterface,
instance : {
execute:function(notification){
this.facade.registerProxy(DataProxy);
this.facade.registerMediator(UIMediator);
this.facade.registerMediator(EchoMediator);
this.facade.registerMediator(MirrorMediator);
}
}
});
var UI=DevShop.SingletonFactory({
extend:DevShop.Facade,
instance:{
ON_KEYUP:"ON_KEY_UP",
ON_KEYUP:"ON_KEYUP",
CMD_KEYUP:"CMD_KEYUP",
initialize:function(){
this.initializeFacade(this);
this.registerCommand(this.CMD_STARTUP,StartUpCmd);
this.registerCommand(this.CMD_KEYUP,KeyUpCmd);
this.sendNotification(this.CMD_STARTUP);
},
onKeyUp:function(){
Expand Down

0 comments on commit d1edc45

Please sign in to comment.