Skip to content

Instantly share code, notes, and snippets.

@MarcoSantarossa
Created January 25, 2019 10:31
Show Gist options
  • Save MarcoSantarossa/d6733e98f6c85eab31a370194f6da050 to your computer and use it in GitHub Desktop.
Save MarcoSantarossa/d6733e98f6c85eab31a370194f6da050 to your computer and use it in GitHub Desktop.
Binder
import UIKit
typealias EmptyClosure = () -> Void
final class MyEW {
let onDo: EmptyClosure
init(onDo: @escaping EmptyClosure) {
self.onDo = onDo
}
}
final class Binder<EventsWrapper> {
private let onBinded: EmptyClosure
var eventsWrapper: EventsWrapper!
init(onBinded: @escaping EmptyClosure) {
self.onBinded = onBinded
}
func bind(eventsWrapper: EventsWrapper) {
self.eventsWrapper = eventsWrapper
onBinded()
}
}
final class VM {
let binder: Binder<MyEW> = {
let binder = Binder<MyEW> {
print("MS: binded")
}
return binder
}()
func doo() {
binder.eventsWrapper.onDo()
}
}
final class V {
func viewDidLoad() {
let mew = MyEW(onDo: { print("MS: ") })
let vm = VM()
vm.binder.bind(eventsWrapper: mew)
vm.doo()
}
}
let v = V()
v.viewDidLoad()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment