Created
February 4, 2011 00:46
-
-
Save cpojer/810537 to your computer and use it in GitHub Desktop.
Sugar for cross-module communication without knowledge of each other.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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