Skip to content

Commit

Permalink
Fix reactive extensions namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
freak4pc authored and rynecheow committed Jan 3, 2021
1 parent 9e69c28 commit 130c500
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
28 changes: 22 additions & 6 deletions Sources/RxRealm/RxRealm.swift
Expand Up @@ -275,13 +275,20 @@ public extension Observable {
}

// MARK: Realm type extensions

public class RxRealm: ReactiveCompatible {

extension Realm {
public var rx: Realm.Rx { .init(self) }

public struct Rx {
private let base: Realm

init(_ base: Realm) {
self.base = base
}
}
}
extension Realm: RealmReactiveCompatible {}

public extension Reactive where Base == Realm {
// MARK: - Instance Reactive Extensions
public extension Realm.Rx {
/**
Returns bindable sink wich adds object sequence to the current Realm
Expand Down Expand Up @@ -381,7 +388,16 @@ public extension Reactive where Base == Realm {
}
}

public extension Reactive where Base == Realm {
// MARK: - Static Reactive Extensions
extension Realm {
public static var rx: RxStatic.Type {
RxStatic.self
}

public struct RxStatic {}
}

public extension Realm.RxStatic {
/**
Returns bindable sink wich adds object sequence to a Realm
Expand Down
8 changes: 4 additions & 4 deletions Tests/RxRealmTests/RxRealmWriteSinks.swift
Expand Up @@ -212,29 +212,29 @@ class RxRealmWriteSinks: XCTestCase {
// write on main scheduler
DispatchQueue.global(qos: .background).async {
_ = Observable.just(UniqueObject(3))
.observeOn(MainScheduler.instance)
.observe(on: MainScheduler.instance)
.subscribe(Realm.rx.add(configuration: conf))
}

// write on bg scheduler
DispatchQueue.main.async {
_ = Observable.just(UniqueObject(4))
.observeOn(ConcurrentDispatchQueueScheduler(queue: DispatchQueue.global(qos: .background)))
.observe(on: ConcurrentDispatchQueueScheduler(queue: DispatchQueue.global(qos: .background)))
.subscribe(Realm.rx.add(configuration: conf))
}

// subscribe on main, write in bg
DispatchQueue.main.async {
_ = Observable.just([UniqueObject(5), UniqueObject(6)])
.observeOn(ConcurrentDispatchQueueScheduler(queue: DispatchQueue.global(qos: .background)))
.observe(on: ConcurrentDispatchQueueScheduler(queue: DispatchQueue.global(qos: .background)))
.subscribe(Realm.rx.add(configuration: conf))
}

let until = Observable.array(from: realm.objects(UniqueObject.self))
.filter { $0.count == 6 }
.delay(.milliseconds(100), scheduler: MainScheduler.instance)

let result = try! items.takeUntil(until).toBlocking(timeout: 1).toArray()
let result = try! items.take(until: until).toBlocking(timeout: 1).toArray()
XCTAssertEqual(result.last!, [1, 2, 3, 4, 5, 6])
}
}

0 comments on commit 130c500

Please sign in to comment.