Skip to content

Commit

Permalink
* reduced the code
Browse files Browse the repository at this point in the history
  • Loading branch information
icanzilb committed Apr 23, 2016
1 parent ab20590 commit c7e7454
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions Pod/Classes/RxRealm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>() -> Observable<T> {
public func asObservable() -> Observable<Self> {
return Observable.create {observer in
let token = self.addNotificationBlock {changeset in

Expand All @@ -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 {
Expand All @@ -59,10 +46,6 @@ public extension NotificationEmitter where Self: RealmCollectionType {
}

public func asObservableArray() -> Observable<Array<Self.Generator.Element>> {
return observable()
}

public func asObservable() -> Observable<Self> {
return observable()
return asObservable().map { Array($0) }
}
}

0 comments on commit c7e7454

Please sign in to comment.