Skip to content

Instantly share code, notes, and snippets.

@cpojer
Created February 4, 2011 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpojer/810537 to your computer and use it in GitHub Desktop.
Save cpojer/810537 to your computer and use it in GitHub Desktop.
Sugar for cross-module communication without knowledge of each other.
(function(){
this.Initiatable = new Class({
isInitiatable: true,
initiator: null,
setInitiator: function(initiator){
this.initiator = initiator || null;
return this;
}.protect(),
getInitiator: function(){
return this.initiator;
},
hasInitiator: function(){
return !!this.initiator;
},
installTo: function(initiator){
return this.setInitiator(initiator);
},
uninstallFrom: function(){
return this.setInitiator();
}
});
}).call(this);
(function(){
this.Initiator = new Class({
initialize: function(){
var events = new Events;
this.$events = {};
this.listen = events.addEvent.overloadSetter();
this.ignore = events.removeEvent.overloadGetter();
this.invoke = events.fireEvent;
},
install: function(instance){
if (instance.isInitiatable) instance.installTo(this);
return this;
},
uninstall: function(instance){
if (instance.isInitiatable) instance.uninstallFrom(this);
return this;
}
});
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment