From b1e1c0fb7046582fe6ffe28b15cc55c364fa9ba6 Mon Sep 17 00:00:00 2001 From: Oliver Foggin Date: Thu, 9 Nov 2023 15:10:17 +0000 Subject: [PATCH 1/3] New reducer --- .../AnalyticsReducer.swift | 1 + .../MultipleAnalyticsReducer.swift | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 Sources/ComposableAnalytics/MultipleAnalyticsReducer.swift diff --git a/Sources/ComposableAnalytics/AnalyticsReducer.swift b/Sources/ComposableAnalytics/AnalyticsReducer.swift index f1c6565..ba31635 100644 --- a/Sources/ComposableAnalytics/AnalyticsReducer.swift +++ b/Sources/ComposableAnalytics/AnalyticsReducer.swift @@ -1,6 +1,7 @@ import Foundation import ComposableArchitecture +@available(*, deprecated) public struct AnalyticsReducer: Reducer { @usableFromInline let toAnalyticsData: (State, Action) -> AnalyticsData? diff --git a/Sources/ComposableAnalytics/MultipleAnalyticsReducer.swift b/Sources/ComposableAnalytics/MultipleAnalyticsReducer.swift new file mode 100644 index 0000000..c26cea5 --- /dev/null +++ b/Sources/ComposableAnalytics/MultipleAnalyticsReducer.swift @@ -0,0 +1,34 @@ +import Foundation +import ComposableArchitecture + +@available(*, deprecated) +public struct MultipleAnalyticsReducer: Reducer { + @usableFromInline + let toAnalyticsData: (State, Action) -> [AnalyticsData]? + + @usableFromInline + @Dependency(\.analyticsClient) var analyticsClient + + @inlinable + public init(_ toAnalyticsData: @escaping (State, Action) -> [AnalyticsData]?) { + self.init(toAnalyticsData: toAnalyticsData, internal: ()) + } + + @usableFromInline + init(toAnalyticsData: @escaping (State, Action) -> [AnalyticsData]?, internal: Void) { + self.toAnalyticsData = toAnalyticsData + } + + @inlinable + public func reduce(into state: inout State, action: Action) -> Effect { + guard let analyticsData = toAnalyticsData(state, action) else { + return .none + } + + return .concatenate( + analyticsData.map { data in + .run { _ in analyticsClient.sendAnalytics(data) } + } + ) + } +} From 6336f1bf2eea3e3e4a6c699868c67aca50317610 Mon Sep 17 00:00:00 2001 From: Oliver Foggin Date: Thu, 9 Nov 2023 15:11:42 +0000 Subject: [PATCH 2/3] un deprecate --- Sources/ComposableAnalytics/MultipleAnalyticsReducer.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/ComposableAnalytics/MultipleAnalyticsReducer.swift b/Sources/ComposableAnalytics/MultipleAnalyticsReducer.swift index c26cea5..862292e 100644 --- a/Sources/ComposableAnalytics/MultipleAnalyticsReducer.swift +++ b/Sources/ComposableAnalytics/MultipleAnalyticsReducer.swift @@ -1,7 +1,6 @@ import Foundation import ComposableArchitecture -@available(*, deprecated) public struct MultipleAnalyticsReducer: Reducer { @usableFromInline let toAnalyticsData: (State, Action) -> [AnalyticsData]? From 26106b33573c6bab61acc0a337693cf599690c78 Mon Sep 17 00:00:00 2001 From: Oliver Foggin Date: Thu, 9 Nov 2023 15:13:44 +0000 Subject: [PATCH 3/3] un deprecate --- Sources/ComposableAnalytics/AnalyticsReducer.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/ComposableAnalytics/AnalyticsReducer.swift b/Sources/ComposableAnalytics/AnalyticsReducer.swift index ba31635..f1c6565 100644 --- a/Sources/ComposableAnalytics/AnalyticsReducer.swift +++ b/Sources/ComposableAnalytics/AnalyticsReducer.swift @@ -1,7 +1,6 @@ import Foundation import ComposableArchitecture -@available(*, deprecated) public struct AnalyticsReducer: Reducer { @usableFromInline let toAnalyticsData: (State, Action) -> AnalyticsData?