Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
maxvol committed Sep 27, 2018
1 parent 7df7194 commit 286ecff
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 45 deletions.
21 changes: 3 additions & 18 deletions RxVision/RxVNCoreMLRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,20 @@
import Vision
import RxSwift

public final class RxVNCoreMLRequest<T>: RxVNRequest {
public final class RxVNCoreMLRequest<T>: RxVNRequest<T> {

typealias Observer = RxVNRequestCompletionHandler<T>.Observer

private var handler: RxVNRequestCompletionHandler<T>?
public lazy var observable: Observable<RequestCompletion<T>> = Observable.create { (observer) in
self.handler = RxVNRequestCompletionHandler<T>(observer: observer)
return Disposables.create()
}
private lazy var _request: VNCoreMLRequest = VNCoreMLRequest(model: self.model, completionHandler: self.handler?.requestCompletionHandler)
private let model: VNCoreMLModel

public init(model: VNCoreMLModel) {
self.model = model
super.init()
}

public var request: VNRequest {
override public var request: VNRequest {
get {
return _request
}
}

public var value: T? {
get {
return self.handler?.value
}
set {
self.handler?.value = newValue
}
}

}
24 changes: 4 additions & 20 deletions RxVision/RxVNDetectTextRectanglesRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,18 @@
import Vision
import RxSwift

public final class RxVNDetectTextRectanglesRequest<T>: RxVNRequest {
public final class RxVNDetectTextRectanglesRequest<T>: RxVNRequest<T> {

typealias Observer = RxVNRequestCompletionHandler<T>.Observer

private var handler: RxVNRequestCompletionHandler<T>?

public lazy var observable: Observable<RequestCompletion<T>> = Observable.create { (observer) in
self.handler = RxVNRequestCompletionHandler<T>(observer: observer)
return Disposables.create()
}
private lazy var _request: VNDetectTextRectanglesRequest = VNDetectTextRectanglesRequest(completionHandler: self.handler?.requestCompletionHandler)

public init() {
override public init() {
super.init()
}

public var request: VNRequest {
override public var request: VNRequest {
get {
return _request
}
}

public var value: T? {
get {
return self.handler?.value
}
set {
self.handler?.value = newValue
}
}

}
30 changes: 26 additions & 4 deletions RxVision/RxVNRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,33 @@
//

import Vision
import RxSwift

public protocol RxVNRequest {
public class RxVNRequest<T> {

typealias Observer = RxVNRequestCompletionHandler<T>.Observer

var handler: RxVNRequestCompletionHandler<T>?

public var value: T? {
get {
return self.handler?.value
}
set {
self.handler?.value = newValue
}
}
public lazy var observable: Observable<RequestCompletion<T>> = Observable.create { (observer) in
self.handler = RxVNRequestCompletionHandler<T>(observer: observer)
return Disposables.create()
}
public var request: VNRequest { get {
preconditionFailure("This method must be overridden")
}
}

init() {
}

associatedtype T

var value: T? { get set }
var request: VNRequest { get }
}
5 changes: 2 additions & 3 deletions RxVision/VNImageRequestHandler+Rx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import RxSwift

extension Reactive where Base: VNImageRequestHandler {

public func perform<R: RxVNRequest>(_ requests: [R], with value: R.T? = nil) throws {
requests.forEach { (r) in
var request = r
public func perform<T>(_ requests: [RxVNRequest<T>], with value: T? = nil) throws {
requests.forEach { (request) in
request.value = value
}
try self.base.perform(requests.map { $0.request })
Expand Down

0 comments on commit 286ecff

Please sign in to comment.