1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-25 06:43:24 +03:00

GH-666 Add some convenience methods

This commit is contained in:
Tae Won Ha 2018-09-30 14:51:30 +02:00
parent 086d6cad3c
commit 261d020385
3 changed files with 22 additions and 8 deletions

View File

@ -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()
}
})

View File

@ -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<Action> {

View File

@ -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?