From c7e7454308021182e40ee2f1bf87408b8ecd8192 Mon Sep 17 00:00:00 2001 From: Marin Todorov Date: Sat, 23 Apr 2016 21:18:11 +0200 Subject: [PATCH] * reduced the code --- Pod/Classes/RxRealm.swift | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/Pod/Classes/RxRealm.swift b/Pod/Classes/RxRealm.swift index 6bc3980..7d656eb 100644 --- a/Pod/Classes/RxRealm.swift +++ b/Pod/Classes/RxRealm.swift @@ -16,12 +16,9 @@ extension List: NotificationEmitter {} extension AnyRealmCollection: NotificationEmitter {} extension Results: NotificationEmitter {} -private protocol ArrayType {} -extension Array: ArrayType {} - public extension NotificationEmitter where Self: RealmCollectionType { - private func observable() -> Observable { + public func asObservable() -> Observable { return Observable.create {observer in let token = self.addNotificationBlock {changeset in @@ -39,17 +36,7 @@ public extension NotificationEmitter where Self: RealmCollectionType { return } - if let value = value as? T { - observer.onNext(value) - return - } - - if case _ = T.self as? ArrayType { - observer.onNext(Array(value) as! T) - return - } - - fatalError("Unexpected Observable type") + observer.onNext(value) } return AnonymousDisposable { @@ -59,10 +46,6 @@ public extension NotificationEmitter where Self: RealmCollectionType { } public func asObservableArray() -> Observable> { - return observable() - } - - public func asObservable() -> Observable { - return observable() + return asObservable().map { Array($0) } } } \ No newline at end of file