Skip to content

Instantly share code, notes, and snippets.

@GeekTree0101
Created July 9, 2019 02:40
Show Gist options
  • Save GeekTree0101/3f72d406f6903c67a66d9548afcfffe1 to your computer and use it in GitHub Desktop.
Save GeekTree0101/3f72d406f6903c67a66d9548afcfffe1 to your computer and use it in GitHub Desktop.
No Archtecture
class TestViewController {
let userInputView = InputView()
let displayOutputView: OutputView()
func bind() {
let state = Presenter.shared.state(type: OutputViewState.self, id: 1)
state.map { $0.title }.bind(to: displayOutputView.rx.title).disposed(by: bag)
}
}
class Presenter {
static let shared = Presenter.init()
// share state
func state<T: ViewStateType>(type: T.Type, id: Identifier) -> Observable<T> { ... }
// dispatch viewState
func dispatch<T: ViewStateType>(_ target: T, qos: DispatchQosClass) { ... }
}
protocol Identifier {
func asIdentifier() -> String
}
extension Int: Identifier {
func asIdentifier() -> String {
return "\($0)"
}
}
extension String: Identifier {
func asIdentifier() -> String {
return self
}
}
protocol ViewStateType {
var id: Identfier { get }
}
struct OutputViewState: ViewStateType {
var id: Identfier
var title: String
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment