-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c9f8a3
commit b1e1c0f
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Sources/ComposableAnalytics/MultipleAnalyticsReducer.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import Foundation | ||
import ComposableArchitecture | ||
|
||
@available(*, deprecated) | ||
public struct MultipleAnalyticsReducer<State, Action>: 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<Action> { | ||
guard let analyticsData = toAnalyticsData(state, action) else { | ||
return .none | ||
} | ||
|
||
return .concatenate( | ||
analyticsData.map { data in | ||
.run { _ in analyticsClient.sendAnalytics(data) } | ||
} | ||
) | ||
} | ||
} |