Created
August 4, 2019 14:02
-
-
Save laevandus/086ea2ec759689121e61f6118595781b 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
protocol KeyValueObservable where Self: AnyObject { | |
/// Stores all the added observations. | |
var observationStore: ObservationStore<Self> { get } | |
/// Sends key-value change notification to all the observers for this key path. | |
func didChangeValue(for keyPath: PartialKeyPath<Self>) | |
/// Adds observer for key path and returns observation token. | |
/// - Note: Observation token is only useful if it is needed to remove observation before observer is deallocated. When observer is deallocated, then observation is removed when next key value change is handled. | |
@discardableResult func addObserver<Observer: AnyObject, Value>(_ observer: Observer, | |
keyPath: KeyPath<Self, Value>, | |
options: Observation.Options, | |
handler: @escaping (Observer, Value) -> Void) -> Observation | |
/// Removes added observation. | |
func removeObservation(_ observation: Observation) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment