1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-01 01:32:04 +03:00

Use per session dispose bag for search stream

This commit is contained in:
Tae Won Ha 2020-01-18 15:30:54 +01:00
parent 2b35773fdd
commit cdf6bcbb00
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44

View File

@ -31,6 +31,10 @@ class OpenQuicklyWindow: NSObject,
required init(source: Observable<StateType>, emitter: ActionEmitter, state: StateType) { required init(source: Observable<StateType>, emitter: ActionEmitter, state: StateType) {
self.emit = emitter.typedEmit() self.emit = emitter.typedEmit()
self.windowController = NSWindowController(windowNibName: NSNib.Name("OpenQuicklyWindow")) self.windowController = NSWindowController(windowNibName: NSNib.Name("OpenQuicklyWindow"))
self.searchStream = self.searchField.rx
.text.orEmpty
.throttle(.milliseconds(1 * 500), latest: true, scheduler: MainScheduler.instance)
.distinctUntilChanged()
super.init() super.init()
@ -47,6 +51,8 @@ class OpenQuicklyWindow: NSObject,
private let emit: (Action) -> Void private let emit: (Action) -> Void
private let disposeBag = DisposeBag() private let disposeBag = DisposeBag()
private let searchStream: Observable<String>
private var perSessionDisposeBag = DisposeBag()
private var cwdPathCompsCount = 0 private var cwdPathCompsCount = 0
private var usesVcsIgnores = true private var usesVcsIgnores = true
private var scanToken = Token() private var scanToken = Token()
@ -100,16 +106,13 @@ class OpenQuicklyWindow: NSObject,
self.cwdPathCompsCount = cwd.pathComponents.count self.cwdPathCompsCount = cwd.pathComponents.count
self.cwdControl.url = cwd self.cwdControl.url = cwd
self.searchField.rx self.searchStream
.text.orEmpty
.throttle(.milliseconds(1 * 500), latest: true, scheduler: MainScheduler.instance)
.distinctUntilChanged()
.observeOn(MainScheduler.instance) .observeOn(MainScheduler.instance)
.subscribe(onNext: { [weak self] pattern in .subscribe(onNext: { [weak self] pattern in
guard let fileService = self?.fileServicesPerRootUrl[cwd] else { return } guard let fileService = self?.fileServicesPerRootUrl[cwd] else { return }
self?.scanAndScore(pattern, with: fileService) self?.scanAndScore(pattern, with: fileService)
}) })
.disposed(by: self.disposeBag) .disposed(by: self.perSessionDisposeBag)
self.windowController.showWindow(self) self.windowController.showWindow(self)
} }
@ -356,6 +359,7 @@ extension OpenQuicklyWindow {
self.unsortedScoredUrls.removeAll() self.unsortedScoredUrls.removeAll()
self.searchField.stringValue = "" self.searchField.stringValue = ""
self.perSessionDisposeBag = DisposeBag()
} }
func windowDidResignKey(_: Notification) { self.window.performClose(self) } func windowDidResignKey(_: Notification) { self.window.performClose(self) }