Skip to content

Instantly share code, notes, and snippets.

@dmytro-anokhin
Created August 19, 2020 22:38
Show Gist options
  • Save dmytro-anokhin/8485d0b6ea7dac7bec4870210543b9f2 to your computer and use it in GitHub Desktop.
Save dmytro-anokhin/8485d0b6ea7dac7bec4870210543b9f2 to your computer and use it in GitHub Desktop.
final class AnyRemoteContent<Value> : RemoteContent {
init<R: RemoteContent>(_ remoteContent: R) where R.ObjectWillChangePublisher == ObjectWillChangePublisher,
R.Value == Value {
objectWillChangeClosure = {
remoteContent.objectWillChange
}
loadingStateClosure = {
remoteContent.loadingState
}
loadClosure = {
remoteContent.load()
}
cancelClosure = {
remoteContent.cancel()
}
}
private let objectWillChangeClosure: () -> ObjectWillChangePublisher
var objectWillChange: ObservableObjectPublisher {
objectWillChangeClosure()
}
private let loadingStateClosure: () -> RemoteContentLoadingState<Value>
var loadingState: RemoteContentLoadingState<Value> {
loadingStateClosure()
}
private let loadClosure: () -> Void
func load() {
loadClosure()
}
private let cancelClosure: () -> Void
func cancel() {
cancelClosure()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment