Created
January 4, 2015 12:12
-
-
Save Somewater/792c5f73e6c4bbad4c56 to your computer and use it in GitHub Desktop.
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
trait EventListener[EventType] { | |
type Listener = (EventType) => Unit | |
var listeners = List.empty[Listener] | |
def +(f: Listener ) = f :: listeners | |
def -(f: Listener) = ... | |
def notify(event: EventType) = listeners.foreach{ l => l(event) } | |
def removeAll = listeners = Nil | |
} | |
class Button { | |
val click = new EventListener[ClickEvent] | |
def update() { | |
.... | |
// был клик по кнопке | |
click.notify() | |
} | |
} | |
val b = new Button | |
def printEvent(ev: Event) = println(ev) | |
b.click += (printEvent _) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment