Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Designable Archetecture

to4iki
October 17, 2017

Designable Archetecture

WIP

to4iki

October 17, 2017
Tweet

More Decks by to4iki

Other Decks in Programming

Transcript

  1. ࣮ݱํ๏ 4 MVW 4 MVC 4 MVP 4 MVVM 4

    CleanArchitecture 4 Flux 4 etc 16
  2. 24

  3. 27

  4. 29

  5. 35

  6. 37

  7. class SearchRepositoryViewModel { ... func fetchRepositories(with query: String) { //

    obserberΛ४උ͢Δ isLoding.value = true let request = GitHubAPI.SearchRepositoriesRequest(query: query, page: 1) Session.shared.rx.send(request) .subscribe( onSuccess: { [unowned self] response in self.repositories.value += response self.isLoding.value = false }, onError: { [unowned self] (error) in self.isLoding.value = false // Τϥʔॲཧ }) .addDisposableTo(disposeBag) } } 39
  8. class SearchRepositoryViewController: UIViewController { ... override func viewDidLoad() { super.viewDidLoad()

    // UISearchBarͷೖྗΛߪಡ searchBar.rx.text.orEmpty.asDriver() .skip(1) .debounce(0.3) .distinctUntilChanged() .drive(onNext: { [unowned self] query in self.viewModel.fetchRepositories(with: query) }) .addDisposableTo(disposeBag) // ViewModelͷisLodingΛߪಡ viewModel.isLoding.asDriver() .drive(indicatorView.rx.isAnimating) .addDisposableTo(disposeBag) } } 41
  9. 45

  10. 47

  11. Data in a Flux application flows in a single direction3

    3 https://facebook.github.io/flux/docs/in-depth-overview.html#content 51
  12. struct CounterActionIncrease: Action {} struct CounterActionDecrease: Action {} class CounterViewController:

    UIViewController, StoreSubscriber { ... @IBAction func increaseButtonTapped(sender: UIButton) { store.dispatch(CounterActionIncrease()) } 53
  13. struct Store { // ActionʹԠͯ͡ঢ়ଶΛmutate // มߋΛdispatch(publish)͢Δ } class CounterViewController:

    UIViewController, StoreSubscriber { ... // ߪಡ override func viewWillAppear(animated: Bool) { store.subscribe(self) } // storeʹมߋ͕͋ͬͨΒݺ͹ΕΔ func newState(state: AppState) { counterLabel.text = "\(state.counter)" } 54
  14. 4 MVC + Observerύλʔϯ 4 Viewͷঢ়ଶͷྲྀΕΛ୯ํ޲ʹ͠ɺॲཧʹΑΔ ঢ়ଶͷมԽΛ༧ଌ͠΍͘͢ͳΔ 4 ๻ͨͪ͸ͦΜͳ஫ҙਂ͘ͳ͍ɻ୯ํ޲ͷσʔλ ϑϩʔΛڧ੍͢Δͷ͕Fluxͷخ͠͞

    4 View͕σʔλͷঢ়ଶΛ؂ࢹ͠ɺมߋ͋ͬͨΑ ͱ௨஌Λड͚औΓඳը͠௚͢ 4 ௨஌Λड͚औΓɺࠩ෼ඳը͢ΔͨΊʹ VirtualDOMͷ࢓૊ΈΛ࢖͍ͬͯΔ 56