Action, state: State?) -> State { } *switch is non-exhausting for simplicity // create a new state if state is nil var state = state ?? State() // switch through desired actions switch action { case let action as ChangeData: }
Action, state: State?) -> State { } *switch is non-exhausting for simplicity // create a new state if state is nil var state = state ?? State() // switch through desired actions switch action { case let action as ChangeData: } // perform state change state.data = action.changedData
Action, state: State?) -> State { } *switch is non-exhausting for simplicity // create a new state if state is nil var state = state ?? State() // switch through desired actions switch action { case let action as ChangeData: } // perform state change state.data = action.changedData // return the new state return state
@IBOutlet weak var label: UILabel! } // subscribe to store, e.g. in `viewWillAppear` func setup() { store.subscribe(self) } // receive state updates from store func newState(state: State) { self.label.text = state.data }
@IBOutlet weak var label: UILabel! } // subscribe to store, e.g. in `viewWillAppear` func setup() { store.subscribe(self) } // receive state updates from store func newState(state: State) { self.label.text = state.data } // dispatch an action to store @IBAction func buttonTap(_ sender: Any) { let action = ChangeData(changedData: "changedData") store.dispatch(action) }
PublishSubject<String>() // subscribe to data subject* data.asObservable() .subscribe(onNext: { element in label.rx.text = element }) *disposing is left out for simplicity
PublishSubject<String>() // subscribe to data subject* data.asObservable() .subscribe(onNext: { element in label.rx.text = element }) // or just bind data subject to label* data.bind(to: label.rx.text) *disposing is left out for simplicity
PublishSubject<String>() // subscribe to data subject* data.asObservable() .subscribe(onNext: { element in label.rx.text = element }) // or just bind data subject to label* data.bind(to: label.rx.text) *disposing is left out for simplicity // trigger an update data.onNext("changedData")
{ let data: String } // state to props mapping private let mapStateToProps = { (state: State) in } return ReRxSwiftViewController.Props( data: state.data )
weak var label: UILabel! } // set up connection with store and mappings let connection = Connection(store: store, mapStateToProps: mapStateToProps, mapDispatchToActions: mapDispatchToActions)
weak var label: UILabel! } // set up connection with store and mappings let connection = Connection(store: store, mapStateToProps: mapStateToProps, mapDispatchToActions: mapDispatchToActions) // establish connection and bind to a label func setup() { self.connection.connect() self.connection.bind(\Props.data, to: self.label.rx.text) }
weak var label: UILabel! } // set up connection with store and mappings let connection = Connection(store: store, mapStateToProps: mapStateToProps, mapDispatchToActions: mapDispatchToActions) // establish connection and bind to a label func setup() { self.connection.connect() self.connection.bind(\Props.data, to: self.label.rx.text) } // dispatch an action @IBAction func buttonTap(_ sender: Any) { self.connection.actions.changeData("changedData") }
Massive View Controllers academy.realm.io/posts/benji-encz-unidirectional-data-flow-swift MVVM is lipstick on a pig sharpfivesoftware.com/2016/07/20/mvvm-is-lipstick-on-a-pig Architecture Wars: A New Hope swifting.io/blog/2016/09/07/architecture-wars-a-new-hope Model View Whatever khanlou.com/2014/03/model-view-whatever