diff --git a/VimR/VimR/MainWindow+Delegates.swift b/VimR/VimR/MainWindow+Delegates.swift index d944ce99..47bca6a6 100644 --- a/VimR/VimR/MainWindow+Delegates.swift +++ b/VimR/VimR/MainWindow+Delegates.swift @@ -56,7 +56,7 @@ extension MainWindow { func bufferListChanged() { self.neoVimView .allBuffers() - .subscribe(onSuccess: { buffers in + .value(onSuccess: { buffers in self.emit(self.uuidAction(for: .setBufferList(buffers.filter { $0.isListed }))) }) } @@ -72,7 +72,7 @@ extension MainWindow { func tabChanged() { self.neoVimView .currentBuffer() - .subscribe(onSuccess: { + .value(onSuccess: { self.newCurrentBuffer($0) }) } @@ -123,11 +123,11 @@ extension MainWindow { func windowDidBecomeMain(_ notification: Notification) { self.emit(self.uuidAction(for: .becomeKey(isFullScreen: self.window.styleMask.contains(.fullScreen)))) - self.neoVimView.didBecomeMain().subscribe() + self.neoVimView.didBecomeMain().trigger() } func windowDidResignMain(_ notification: Notification) { - self.neoVimView.didResignMain().subscribe() + self.neoVimView.didResignMain().trigger() } func windowDidMove(_ notification: Notification) { @@ -144,7 +144,7 @@ extension MainWindow { func windowShouldClose(_: NSWindow) -> Bool { guard (self.neoVimView.isCurrentBufferDirty().syncValue() ?? false) else { - self.neoVimView.closeCurrentTab().subscribe() + self.neoVimView.closeCurrentTab().trigger() return false } @@ -157,7 +157,7 @@ extension MainWindow { discardAndCloseButton.keyEquivalent = "d" alert.beginSheetModal(for: self.window, completionHandler: { response in if response == .alertSecondButtonReturn { - self.neoVimView.closeCurrentTabWithoutSaving().subscribe() + self.neoVimView.closeCurrentTabWithoutSaving().trigger() } }) diff --git a/VimR/VimR/MainWindow.swift b/VimR/VimR/MainWindow.swift index 9b1ce399..365c4e39 100644 --- a/VimR/VimR/MainWindow.swift +++ b/VimR/VimR/MainWindow.swift @@ -292,7 +292,7 @@ class MainWindow: NSObject, return .empty() } - .subscribe() + .trigger() let usesTheme = state.appearance.usesTheme let themePrefChanged = state.appearance.usesTheme != self.usesTheme @@ -362,7 +362,7 @@ class MainWindow: NSObject, return .empty() } - .subscribe() + .trigger() } func uuidAction(for action: Action) -> UuidAction { diff --git a/VimR/VimR/RxSwiftCommons.swift b/VimR/VimR/RxSwiftCommons.swift index b0c14179..f651b15f 100644 --- a/VimR/VimR/RxSwiftCommons.swift +++ b/VimR/VimR/RxSwiftCommons.swift @@ -50,6 +50,13 @@ extension PrimitiveSequence where Element == Never, TraitType == CompletableTrai throw e } } + + func trigger( + onCompleted: (() -> Void)? = nil, + onError: ((Error) -> Void)? = nil + ) { + self.subscribe(onCompleted: onCompleted, onError: onError) + } } extension PrimitiveSequence where TraitType == SingleTrait { @@ -65,6 +72,13 @@ extension PrimitiveSequence where TraitType == SingleTrait { .ignoreElements() } + func value( + onSuccess: ((Element) -> Void)? = nil, + onError: ((Error) -> Void)? = nil + ) { + self.subscribe(onSuccess: onSuccess, onError: onError) + } + func syncValue() -> Element? { var trigger = false var value: Element?