Skip to content

Commit f64bf1c

Browse files
authored
Merge pull request #219 from fabianmuecke/add-observe-from-arguments
2 parents ab77446 + 32c6a9f commit f64bf1c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Sources/RxRealm/RxRealm.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,17 +509,19 @@ public extension Observable where Element: Object {
509509
- parameter object: A Realm Object to observe
510510
- parameter emitInitialValue: whether the resulting `Observable` should emit its first element synchronously (e.g. better for UI bindings)
511511
- parameter properties: changes to which properties would triger emitting a .next event
512+
- parameter queue: The serial dispatch queue to receive notification on. If `nil`, notifications are delivered to the current thread.
512513
- returns: `Observable<Object>` will emit any time the observed object changes + one initial emit upon subscription
513514
*/
514515

515516
static func from(object: Element, emitInitialValue: Bool = true,
516-
properties: [String]? = nil) -> Observable<Element> {
517+
properties: [String]? = nil,
518+
on queue: DispatchQueue? = nil) -> Observable<Element> {
517519
return RxSwift.Observable<Element>.create { observer in
518520
if emitInitialValue {
519521
observer.onNext(object)
520522
}
521523

522-
let token = object.observe { change in
524+
let token = object.observe(on: queue) { change in
523525
switch change {
524526
case let .change(_, changedProperties):
525527
if let properties = properties, !changedProperties.contains(where: { properties.contains($0.name) }) {
@@ -544,12 +546,14 @@ public extension Observable where Element: Object {
544546
Returns an `Observable<PropertyChange>` that emits the object `PropertyChange`s.
545547

546548
- parameter object: A Realm Object to observe
549+
- parameter queue: The serial dispatch queue to receive notification on. If `nil`, notifications are delivered to the current thread.
547550
- returns: `Observable<PropertyChange>` will emit any time a change is detected on the object
548551
*/
549552

550-
static func propertyChanges(object: Element) -> Observable<PropertyChange> {
553+
static func propertyChanges(object: Element,
554+
on queue: DispatchQueue? = nil) -> Observable<PropertyChange> {
551555
return RxSwift.Observable<PropertyChange>.create { observer in
552-
let token = object.observe { change in
556+
let token = object.observe(on: queue) { change in
553557
switch change {
554558
case let .change(_, changes):
555559
for change in changes {

0 commit comments

Comments
 (0)