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

Realm Centered Design

Realm Centered Design

Realm, RxSwift, RxRealm MVVM

yohei sugigami

August 23, 2016
Tweet

More Decks by yohei sugigami

Other Decks in Technology

Transcript

  1. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 Aը໘ Bը໘

    WriteTx Notification Aը໘ͰͷมߋΛBը໘ʹ௨஌Ͱ͖Δ
  2. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 Code example

    ͱ͘ʹ഑ྻσʔλͷ؂ࢹͷ ࠩ෼Index௨஌͕͢͹Β͍͠ʂ
  3. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 try! Realm().objects(ContactRealm).asObservableChangeset()

    .subscribeNext { [weak self] results, changeset in guard let tableView = self?.tableView else { return } self?.results = results if let changeset = changeset { tableView.beginUpdates() tableView.insertRowsAtIndexPaths(…, withRowAnimation: .Automatic) tableView.deleteRowsAtIndexPaths(…, withRowAnimation: .Automatic) tableView.reloadRowsAtIndexPaths(…, withRowAnimation: .Automatic) tableView.endUpdates() } else { tableView.reloadData() } }.addDisposableTo(disposeBag) NotificationΛRxSwiftͷObservableͱͯ͠ѻ͑Δʂ
  4. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 // Simple

    Create [MessageRealm("hello"), MessageRealm("world")] .toObservable() .subscribe(Realm.rx_add()) // With API let request = API.Endpoint.MessagesRequest().request() Session.rx_response(request) .subscribe(Realm.rx_add()) RealmObjectͷCRUD΋RwSwiftͷ؅ཧԼʹʂ
  5. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 View ViewModel

    Aը໘ Bը໘ Cը໘ Subscribe ௨৴தͳͲը໘ݻ༗ͷঢ়ଶ RxSwift w/ MVVM ը໘ͷओཁͳσʔλ ը໘ԣஅతͳσʔλͷѻ͍͕೉͍͠ ʢLike໰୊ʣ
  6. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 View ViewModel

    Aը໘ Bը໘ Cը໘ Subscribe ը໘ԣஅతͳঢ়ଶɾσʔλ ௨৴தͳͲը໘ݻ༗ͷঢ়ଶ earth (Singleton) ஍ٿ͸Ͱ͔͍ͬγϯάϧτϯ RxSwift w/ MVVM(earth) ը໘ͷओཁͳσʔλ Global ViewModel ©
  7. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 View ViewModel

    Aը໘ Bը໘ Cը໘ Observable Store Subscribe ը໘ԣஅͳঢ়ଶ ը໘ͷओཁͳσʔλ ௨৴தͳͲը໘ݻ༗ͷঢ়ଶ earth (Singleton) ஍ٿ͸Ͱ͔͍ͬγϯάϧτϯ RxSwift+RxRealm w/ MVVM (RxRealm)
  8. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 Redux -

    Single source of truth - State is read-only - Changes are made with pure functions ΞϓϦͷঢ়ଶɾσʔλΛอ࣋͢ΔStore͸ͨͩ1ͭ Inspired by
  9. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 ΫϥΠΞϯτΞϓϦ͸ঢ়ଶɾσʔλ؅ཧ͸ෳࡶ -

    ෭࣍తͳ࢈෺ͱͯ͠ɺRxDatasourceʹΑΔTableViewBinding͸࢖͍ʹ ͍͘ͷͰRealmNotificationʹΑΔTableViewReload͸ѻ͍΍͍͢ 㱺 Rx w/ MVVMͱReduxͷ͍͍ͱ͜ΖͲΓΛ͍ͨ͠ - ը໘ʹඥͮ͘σʔλͱঢ়ଶΛViewModelʹ٧ΊΔͷ΋ɺΞϓϦશମͷσʔλͱ ঢ়ଶΛStoreʹ٧ΊΔͷ΋྆ۃ୺Ͱਏ͍ - “஍ٿ͸Ͱ͔͍ͬγϯάϧτϯ”͸ΤϙοΫϝΠΩϯά - ը໘ʹඥͮ͘ঢ়ଶΛ֤ViewModelʹσʔλΛStoreʢRealm or Singletonʣ ʹͱ͍͏ં஭ҊΛߟ͑ͨ ·ͱΊ