SimpleTwoWayBindingIOS
SimpleTwoWayBindingIOS copied to clipboard
Observable doesn't support optional ObservedType
Hey, right now this library has Observable<ObservedType> which might support on theory observing optional types. The problem is that when the value is being set, you have this check:
public var value: ObservedType? {
didSet {
if let value = value {
notifyObservers(value)
}
}
}
That doesn't allow the observing instance to react to the "cleanup" of this model.
For example if ObservedType = UIImage
, and I want to clean up the image from the UIImageView:
viewModel.thumbnailImage.bind { [weak self] _ , image in
self?.imageView.image = image
}
This code will not be invoked for a nil value.
Do you have any plans to support setting nil value to Observable?
Yes, as of now, it doesn't support the notion of null(nil) as a valid value. There needs to be an explicit way of un-setting the value and notify observers. which would also put the onus on observers to be vary of fact that the value recieved can be nil. I still need to figure out if this should be part of the default behavior and if yes, should it be a strong abstraction (Optional value?)