Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
make sure datastore is ready to provide item (#970)
Browse files Browse the repository at this point in the history
* make sure datastore is ready to provide item

* shift take(1)

* resolve some foregrounding issues
  • Loading branch information
sashei committed May 14, 2019
1 parent f2778c3 commit 69d6554
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
3 changes: 1 addition & 2 deletions Shared/Store/BaseDataStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ extension BaseDataStore {

self.lifecycleStore.lifecycleEvents
.filter { $0 == .foreground }
.flatMap { _ in self.storageState }
.take(1)
.flatMap { _ in self.storageState.take(1) }
.subscribe(onNext: { [weak self] state in
guard state != .Unprepared else { return }

Expand Down
7 changes: 5 additions & 2 deletions lockbox-ios/Presenter/ItemDetailPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ class ItemDetailPresenter {
}

func onViewReady() {
let itemObservable = self.itemDetailStore.itemDetailId
.flatMap { self.dataStore.get($0) }
let itemObservable = self.dataStore.locked
.filter { !$0 }
.take(1)
.flatMap { _ in self.itemDetailStore.itemDetailId }
.flatMap { self.dataStore.get($0) }

let itemDriver = itemObservable.asDriver(onErrorJustReturn: nil)
let viewConfigDriver = Driver.combineLatest(itemDriver.filterNil(), self.itemDetailStore.itemDetailDisplay)
Expand Down
1 change: 1 addition & 0 deletions lockbox-ios/Presenter/RootPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class RootPresenter {
.disposed(by: self.disposeBag)

self.dataStore.storageState
.distinctUntilChanged()
.map({ (storageState) -> [Action] in
switch storageState {
case .Unprepared, .Locked:
Expand Down
10 changes: 7 additions & 3 deletions lockbox-iosTests/ItemDetailPresenterSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,19 @@ class ItemDetailPresenterSpec: QuickSpec {
}

class FakeDataStore: DataStore {
var onItemStub: PublishSubject<LoginRecord?>
var onItemStub = PublishSubject<LoginRecord?>()
var lockedStub = ReplaySubject<Bool>.create(bufferSize: 1)
var loginIDArg: String?

init() {
self.onItemStub = PublishSubject<LoginRecord?>()
super.init()

self.disposeBag = DisposeBag()
}

override var locked: Observable<Bool> {
return lockedStub.asObservable()
}

override func get(_ id: String) -> Observable<LoginRecord?> {
self.loginIDArg = id
return onItemStub.asObservable()
Expand Down Expand Up @@ -340,6 +343,7 @@ class ItemDetailPresenterSpec: QuickSpec {

self.itemDetailStore.itemDetailIdStub.onNext("1234")
self.sizeClassStore.shouldDisplaySidebarStub.onNext(false)
self.dataStore.lockedStub.onNext(false)
self.subject.onViewReady()
}

Expand Down

0 comments on commit 69d6554

Please sign in to comment.