From 6cdb0dd823243a2d93c606f5f03b851cdb9b8f05 Mon Sep 17 00:00:00 2001 From: Vasyl Myronchuk Date: Thu, 15 Nov 2018 10:14:26 +0100 Subject: [PATCH] Eliminated RealmBindingObserver in favour of RxCocoa Binder. --- Pod/Classes/Reactive+RxRealmDataSources.swift | 21 ++++++++++--------- Pod/Classes/RealmBindObserver.swift | 1 + 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Pod/Classes/Reactive+RxRealmDataSources.swift b/Pod/Classes/Reactive+RxRealmDataSources.swift index 4ebe663..0028e0e 100644 --- a/Pod/Classes/Reactive+RxRealmDataSources.swift +++ b/Pod/Classes/Reactive+RxRealmDataSources.swift @@ -63,16 +63,16 @@ import Cocoa extension Reactive where Base: NSTableView { public func realmChanges(_ dataSource: RxTableViewRealmDataSource) - -> RealmBindObserver, RxTableViewRealmDataSource> { + -> Binder> { base.delegate = dataSource base.dataSource = dataSource - return RealmBindObserver(dataSource: dataSource) {ds, results, changes in + return Binder(base) { tableView, element in if dataSource.tableView == nil { - dataSource.tableView = self.base + dataSource.tableView = tableView } - ds.applyChanges(items: AnyRealmCollection(results), changes: changes) + dataSource.applyChanges(items: element.0, changes: element.1) } } } @@ -80,14 +80,15 @@ extension Reactive where Base: NSTableView { extension Reactive where Base: NSCollectionView { public func realmChanges(_ dataSource: RxCollectionViewRealmDataSource) - -> RealmBindObserver, RxCollectionViewRealmDataSource> { + -> Binder> { - return RealmBindObserver(dataSource: dataSource) {ds, results, changes in - if ds.collectionView == nil { - ds.collectionView = self.base + base.dataSource = dataSource + + return Binder(base) { collectionView, element in + if dataSource.collectionView == nil { + dataSource.collectionView = collectionView } - ds.collectionView?.dataSource = ds - ds.applyChanges(items: AnyRealmCollection(results), changes: changes) + dataSource.applyChanges(items: element.0, changes: element.1) } } } diff --git a/Pod/Classes/RealmBindObserver.swift b/Pod/Classes/RealmBindObserver.swift index a60b378..cdaee63 100644 --- a/Pod/Classes/RealmBindObserver.swift +++ b/Pod/Classes/RealmBindObserver.swift @@ -12,6 +12,7 @@ import RxSwift import RxCocoa import RxRealm +@available(*, deprecated, message: "use RxCocoa Binder instead") public class RealmBindObserver: ObserverType { typealias BindingType = (DS, C, RealmChangeset?) -> Void public typealias E = (C, RealmChangeset?)