Created
June 19, 2013 09:44
-
-
Save djtal/5813064 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Mediator= | |
suscribers : {} | |
publish : (event, args...) -> | |
callback.call(args...) for callback in @suscribers[event] if @suscribers[event]? | |
suscribe : (event, callback) -> | |
@suscribers[event] = [] unless @suscribers[event]? | |
@suscribers[event].push(callback) | |
unsuscribe : (event, callback) -> | |
@suscribers[event] -= callback | |
cb1 = (args...) -> console.log("cb1", args...) | |
cb2 = (args...) -> console.log("cb2", args...) | |
Mediator.suscribe("toto", cb1) | |
Mediator.suscribe("toto", cb2) | |
Mediator.publish("toto", 1,2,3) | |
Mediator.publish("tata", 1,2,3) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment