Created
January 25, 2019 10:31
-
-
Save MarcoSantarossa/d6733e98f6c85eab31a370194f6da050 to your computer and use it in GitHub Desktop.
Binder
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
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