From 8f5362fc501831cbd2f50722a970d26ab9fb4f5d Mon Sep 17 00:00:00 2001 From: Maxim Khatskevich Date: Sat, 17 Feb 2024 21:25:01 +0100 Subject: [PATCH 1/2] [REMOVE] unnecessary `as` helper for mutations observing --- .../XCEUniFlow/0_Helpers/Publisher+Dispatcher.swift | 11 ----------- Sources/XCEUniFlow/4_Dispatcher/Dispatcher.swift | 6 +++++- .../InternalBindingBDD_WhenContext.swift | 2 +- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Sources/XCEUniFlow/0_Helpers/Publisher+Dispatcher.swift b/Sources/XCEUniFlow/0_Helpers/Publisher+Dispatcher.swift index e2ef844..773f1ba 100644 --- a/Sources/XCEUniFlow/0_Helpers/Publisher+Dispatcher.swift +++ b/Sources/XCEUniFlow/0_Helpers/Publisher+Dispatcher.swift @@ -102,17 +102,6 @@ extension Publisher where Output == ProcessedActionReport, Failure == Never } } -public -extension Publisher where Output == StateStorage.History.Element, Failure == Never -{ - func `as`( - _: T.Type - ) -> AnyPublisher { - - compactMap(T.init(from:)).eraseToAnyPublisher() - } -} - // MARK: - Access log - Processed - get features statuses (dashboard) public diff --git a/Sources/XCEUniFlow/4_Dispatcher/Dispatcher.swift b/Sources/XCEUniFlow/4_Dispatcher/Dispatcher.swift index 88bb2b2..d824868 100644 --- a/Sources/XCEUniFlow/4_Dispatcher/Dispatcher.swift +++ b/Sources/XCEUniFlow/4_Dispatcher/Dispatcher.swift @@ -200,7 +200,11 @@ extension Dispatcher /// within scope of this dispatcher. func on( _: T.Type) -> AnyPublisher { - accessLog.onProcessed.perEachMutation.as(T.self) + accessLog + .onProcessed + .perEachMutation + .compactMap(T.init(from:)) + .eraseToAnyPublisher() } } diff --git a/Sources/XCEUniFlow/7_InternalBindings/InternalBindingBDD_WhenContext.swift b/Sources/XCEUniFlow/7_InternalBindings/InternalBindingBDD_WhenContext.swift index 3add63e..af4be11 100644 --- a/Sources/XCEUniFlow/7_InternalBindings/InternalBindingBDD_WhenContext.swift +++ b/Sources/XCEUniFlow/7_InternalBindings/InternalBindingBDD_WhenContext.swift @@ -57,7 +57,7 @@ extension InternalBindingBDD description: description, when: { $0.onProcessed .perEachMutation - .as(M.self) + .compactMap(M.init(from:)) .eraseToAnyPublisher() } ) From c5f9dd3ac13f4bb450f41ebf9b48e5f5549f9e0a Mon Sep 17 00:00:00 2001 From: Maxim Khatskevich Date: Sat, 17 Feb 2024 23:14:48 +0100 Subject: [PATCH 2/2] [ADD] `when` convenience helper for mutations observing --- Sources/XCEUniFlow/4_Dispatcher/Dispatcher.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sources/XCEUniFlow/4_Dispatcher/Dispatcher.swift b/Sources/XCEUniFlow/4_Dispatcher/Dispatcher.swift index d824868..f438b24 100644 --- a/Sources/XCEUniFlow/4_Dispatcher/Dispatcher.swift +++ b/Sources/XCEUniFlow/4_Dispatcher/Dispatcher.swift @@ -206,6 +206,16 @@ extension Dispatcher .compactMap(T.init(from:)) .eraseToAnyPublisher() } + + /// Designeted convenience shortcut for observing all mutations + /// within scope of this dispatcher. + @available(macOS 12.0, *) + func when( _: T.Type) async -> T? + { + await on(T.self) // filter for certain mutation type + .values + .first { _ in true } // no further filtering is necessary + } } // MARK: - Internal bindings management