Created
July 8, 2014 15:58
-
-
Save gscalzo/fe395e0600ea6347bc54 to your computer and use it in GitHub Desktop.
Need For Mixins: what I want
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
protocol Observable { | |
func observe(onUpdate: (Void) -> Void) -> String | |
func unobserve(key: String) | |
} | |
class ObservableDispatcher { | |
var observerClosures: Dictionary<String, (Void) -> Void> = Dictionary<String, (Void) -> Void>() | |
func observe(onUpdate: (Void) -> Void) -> String { | |
let key = "key_\(observerClosures.count+1)_key" | |
observerClosures[key] = onUpdate | |
return key | |
} | |
func unobserve(key: String) { | |
observerClosures.removeValueForKey(key) | |
} | |
func update() { | |
for closure in self.observerClosures.values { | |
closure() | |
} | |
} | |
} | |
class HDSViewModel: Observable { | |
@delegate let dispatcher = ObservableDispatcher() | |
func doSometing() { | |
// Do Something | |
self.dispatcher.update() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment