Realm Centered Design

Realm Centered Design

Realm, RxSwift, RxRealm MVVM

Acbf3391de0494432a92221ffe89f34e?s=128

yohei sugigami

August 23, 2016
Tweet

Transcript

  1. 5.

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

    WriteTx Notification Aը໘ͰͷมߋΛBը໘ʹ௨஌Ͱ͖Δ
  2. 6.

    γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 Code example

    ͱ͘ʹ഑ྻσʔλͷ؂ࢹͷ ࠩ෼Index௨஌͕͢͹Β͍͠ʂ
  3. 8.

    γΰτͰίίϩΦυϧ 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. 9.

    γΰτͰίίϩΦυϧ 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. 11.

    γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 View ViewModel

    Aը໘ Bը໘ Cը໘ Subscribe ௨৴தͳͲը໘ݻ༗ͷঢ়ଶ RxSwift w/ MVVM ը໘ͷओཁͳσʔλ ը໘ԣஅతͳσʔλͷѻ͍͕೉͍͠ ʢLike໰୊ʣ
  6. 12.

    γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 View ViewModel

    Aը໘ Bը໘ Cը໘ Subscribe ը໘ԣஅతͳঢ়ଶɾσʔλ ௨৴தͳͲը໘ݻ༗ͷঢ়ଶ earth (Singleton) ஍ٿ͸Ͱ͔͍ͬγϯάϧτϯ RxSwift w/ MVVM(earth) ը໘ͷओཁͳσʔλ Global ViewModel ©
  7. 13.

    γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 View ViewModel

    Aը໘ Bը໘ Cը໘ Observable Store Subscribe ը໘ԣஅͳঢ়ଶ ը໘ͷओཁͳσʔλ ௨৴தͳͲը໘ݻ༗ͷঢ়ଶ earth (Singleton) ஍ٿ͸Ͱ͔͍ͬγϯάϧτϯ RxSwift+RxRealm w/ MVVM (RxRealm)
  8. 14.

    γΰτͰίίϩΦυϧ 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. 15.

    γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 ΫϥΠΞϯτΞϓϦ͸ঢ়ଶɾσʔλ؅ཧ͸ෳࡶ -

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