Skip to content

Commit

Permalink
Eliminated RealmBindingObserver in favour of RxCocoa Binder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Granfalloner committed Nov 15, 2018
1 parent 022964a commit 6cdb0dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Pod/Classes/Reactive+RxRealmDataSources.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,32 @@ import Cocoa
extension Reactive where Base: NSTableView {

public func realmChanges<E>(_ dataSource: RxTableViewRealmDataSource<E>)
-> RealmBindObserver<E, AnyRealmCollection<E>, RxTableViewRealmDataSource<E>> {
-> Binder<RealmChange<E>> {

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<E>(results), changes: changes)
dataSource.applyChanges(items: element.0, changes: element.1)
}
}
}

extension Reactive where Base: NSCollectionView {

public func realmChanges<E>(_ dataSource: RxCollectionViewRealmDataSource<E>)
-> RealmBindObserver<E, AnyRealmCollection<E>, RxCollectionViewRealmDataSource<E>> {
-> Binder<RealmChange<E>> {

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<E>(results), changes: changes)
dataSource.applyChanges(items: element.0, changes: element.1)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Pod/Classes/RealmBindObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import RxSwift
import RxCocoa
import RxRealm

@available(*, deprecated, message: "use RxCocoa Binder instead")
public class RealmBindObserver<O: Object, C: RealmCollection, DS>: ObserverType {
typealias BindingType = (DS, C, RealmChangeset?) -> Void
public typealias E = (C, RealmChangeset?)
Expand Down

0 comments on commit 6cdb0dd

Please sign in to comment.