PR notes #1
This commit is contained in:
parent
72c0d4fc6e
commit
e4c2fd8f67
|
|
@ -50,22 +50,24 @@ public class FixedPageCursor<Cursor: CursorType>: CursorType {
|
|||
}
|
||||
|
||||
public func loadNextBatch() -> Single<[Cursor.Element]> {
|
||||
if exhausted {
|
||||
return .error(CursorError.exhausted)
|
||||
}
|
||||
return Single.deferred {
|
||||
if self.exhausted {
|
||||
return .error(CursorError.exhausted)
|
||||
}
|
||||
|
||||
let restOfLoaded = cursor.count - count
|
||||
let restOfLoaded = self.cursor.count - self.count
|
||||
|
||||
if restOfLoaded >= pageSize || cursor.exhausted {
|
||||
let startIndex = count
|
||||
count += min(restOfLoaded, pageSize)
|
||||
if restOfLoaded >= self.pageSize || self.cursor.exhausted {
|
||||
let startIndex = self.count
|
||||
self.count += min(restOfLoaded, self.pageSize)
|
||||
|
||||
return .just(cursor[startIndex..<count])
|
||||
}
|
||||
return .just(self.cursor[startIndex..<self.count])
|
||||
}
|
||||
|
||||
return cursor.loadNextBatch()
|
||||
.flatMap { _ in
|
||||
self.loadNextBatch()
|
||||
return self.cursor.loadNextBatch()
|
||||
.flatMap { _ in
|
||||
self.loadNextBatch()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,13 +51,15 @@ public class SingleLoadCursor<Element>: ResettableCursorType {
|
|||
}
|
||||
|
||||
public func loadNextBatch() -> Single<[Element]> {
|
||||
if exhausted {
|
||||
return .error(CursorError.exhausted)
|
||||
}
|
||||
return Single.deferred {
|
||||
if self.exhausted {
|
||||
return .error(CursorError.exhausted)
|
||||
}
|
||||
|
||||
return loadingObservable.do(onNext: { [weak self] newItems in
|
||||
self?.onGot(result: newItems)
|
||||
})
|
||||
return self.loadingObservable.do(onNext: { [weak self] newItems in
|
||||
self?.onGot(result: newItems)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private func onGot(result: [Element]) {
|
||||
|
|
|
|||
|
|
@ -47,15 +47,17 @@ public class StaticCursor<Element>: ResettableCursorType {
|
|||
}
|
||||
|
||||
public func loadNextBatch() -> Single<[Element]> {
|
||||
if exhausted {
|
||||
return .error(CursorError.exhausted)
|
||||
return Single.deferred {
|
||||
if self.exhausted {
|
||||
return .error(CursorError.exhausted)
|
||||
}
|
||||
|
||||
self.count = self.content.count
|
||||
|
||||
self.exhausted = true
|
||||
|
||||
return .just(self.content)
|
||||
}
|
||||
|
||||
count = content.count
|
||||
|
||||
exhausted = true
|
||||
|
||||
return .just(content)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue