From 7e3b08e8bda0d154dbf2f3a31d3ce43d0f0a05cd Mon Sep 17 00:00:00 2001 From: "Alkenso (Vladimir Vashurkin)" Date: Thu, 26 Oct 2023 09:39:39 +0300 Subject: [PATCH] Improve ProxyPublisher init --- .../Combine/Extensions - Publisher.swift | 7 +++++++ Sources/SpellbookFoundation/Combine/Proxies.swift | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/SpellbookFoundation/Combine/Extensions - Publisher.swift b/Sources/SpellbookFoundation/Combine/Extensions - Publisher.swift index 876298c..8aef3df 100644 --- a/Sources/SpellbookFoundation/Combine/Extensions - Publisher.swift +++ b/Sources/SpellbookFoundation/Combine/Extensions - Publisher.swift @@ -22,6 +22,13 @@ import Combine +@available(macOS 10.15, iOS 13, tvOS 13.0, watchOS 6.0, *) +extension Publisher { + public func eraseToAnyPublisher(attachingContext context: Any?) -> AnyPublisher { + ProxyPublisher(self, context: context).eraseToAnyPublisher() + } +} + @available(macOS 10.15, iOS 13, tvOS 13.0, watchOS 6.0, *) extension Publisher where Output: Equatable, Failure == Never { /// Publishes value changes in order it receives the values diff --git a/Sources/SpellbookFoundation/Combine/Proxies.swift b/Sources/SpellbookFoundation/Combine/Proxies.swift index e804172..539a2f7 100644 --- a/Sources/SpellbookFoundation/Combine/Proxies.swift +++ b/Sources/SpellbookFoundation/Combine/Proxies.swift @@ -30,7 +30,7 @@ public struct ProxyPublisher: Publisher { public let proxy: P public var context: Any? - public init(_ publisher: P) { + public init(_ publisher: P, context: Any? = nil) { proxy = publisher }