Share
Embed
Transcript
16 slides
-
yohei SUGIGAMI Realm Centered Design RxSwift+RxRealm(RealmNotification) Aug. 23, 2016 @
Wantedly potatotips #32 Realmத৺ઃܭ -
γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 Aը໘ Bը໘
WriteTx Notification Aը໘ͰͷมߋΛBը໘ʹ௨Ͱ͖Δ -
γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 Code example
ͱ͘ʹྻσʔλͷࢹͷ ࠩIndex௨͕͢Β͍͠ʂ -
γΰτͰίίϩΦυϧ 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ͱͯ͠ѻ͑Δʂ -
γΰτͰίίϩΦυϧ 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ͷCRUDRwSwiftͷཧԼʹʂ -
γΰτͰίίϩΦυϧ B Launch iPhone3G iOS Developer since mid 2008 RxSwift
MVVM Realm Centered Design RxRealm -
γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 View ViewModel
Aը໘ Bը໘ Cը໘ Subscribe ௨৴தͳͲը໘ݻ༗ͷঢ়ଶ RxSwift w/ MVVM ը໘ͷओཁͳσʔλ ը໘ԣஅతͳσʔλͷѻ͍͕͍͠ ʢLikeʣ -
γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 View ViewModel
Aը໘ Bը໘ Cը໘ Subscribe ը໘ԣஅతͳঢ়ଶɾσʔλ ௨৴தͳͲը໘ݻ༗ͷঢ়ଶ earth (Singleton) ٿͰ͔͍ͬγϯάϧτϯ RxSwift w/ MVVM(earth) ը໘ͷओཁͳσʔλ Global ViewModel © -
γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 View ViewModel
Aը໘ Bը໘ Cը໘ Observable Store Subscribe ը໘ԣஅͳঢ়ଶ ը໘ͷओཁͳσʔλ ௨৴தͳͲը໘ݻ༗ͷঢ়ଶ earth (Singleton) ٿͰ͔͍ͬγϯάϧτϯ RxSwift+RxRealm w/ MVVM (RxRealm) -
γΰτͰίίϩΦυϧ 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 -
γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 ΫϥΠΞϯτΞϓϦঢ়ଶɾσʔλཧෳࡶ -
෭࣍తͳ࢈ͱͯ͠ɺRxDatasourceʹΑΔTableViewBinding͍ʹ ͍͘ͷͰRealmNotificationʹΑΔTableViewReloadѻ͍͍͢ 㱺 Rx w/ MVVMͱReduxͷ͍͍ͱ͜ΖͲΓΛ͍ͨ͠ - ը໘ʹඥͮ͘σʔλͱঢ়ଶΛViewModelʹ٧ΊΔͷɺΞϓϦશମͷσʔλͱ ঢ়ଶΛStoreʹ٧ΊΔͷ྆ۃͰਏ͍ - “ٿͰ͔͍ͬγϯάϧτϯ”ΤϙοΫϝΠΩϯά - ը໘ʹඥͮ͘ঢ়ଶΛ֤ViewModelʹσʔλΛStoreʢRealm or Singletonʣ ʹͱ͍͏ંҊΛߟ͑ͨ ·ͱΊ