@@ -3,35 +3,55 @@ import Foundation
33import SwiftUI
44import XCTestDynamicOverlay
55
6- /// A type that encapsulates a unit of work that can be run in the outside world, and can feed
7- /// actions back to the ``Store``.
8- ///
9- /// Effects are the perfect place to do side effects, such as network requests, saving/loading
10- /// from disk, creating timers, interacting with dependencies, and more. They are returned from
11- /// reducers so that the ``Store`` can perform the effects after the reducer is done running.
12- ///
13- /// There are 2 distinct ways to create an `Effect`: one using Swift's native concurrency tools, and
14- /// the other using Apple's Combine framework:
15- ///
16- /// * If using Swift's native structured concurrency tools then there are 3 main ways to create an
17- /// effect, depending on if you want to emit one single action back into the system, or any number
18- /// of actions, or just execute some work without emitting any actions:
19- /// * ``EffectPublisher/task(priority:operation:catch:file:fileID:line:)``
20- /// * ``EffectPublisher/run(priority:operation:catch:file:fileID:line:)``
21- /// * ``EffectPublisher/fireAndForget(priority:_:)``
22- /// * If using Combine in your application, in particular for the dependencies of your feature
23- /// then you can create effects by making use of any of Combine's operators, and then erasing the
24- /// publisher type to ``EffectPublisher`` with either `eraseToEffect` or `catchToEffect`. Note that
25- /// the Combine interface to ``EffectPublisher`` is considered soft deprecated, and you should
26- /// eventually port to Swift's native concurrency tools.
27- ///
28- /// > Important: ``Store`` is not thread safe, and so all effects must receive values on the same
29- /// thread. This is typically the main thread, **and** if the store is being used to drive UI then
30- /// it must receive values on the main thread.
31- /// >
32- /// > This is only an issue if using the Combine interface of ``EffectPublisher`` as mentioned
33- /// above. If you are using Swift's concurrency tools and the `.task`, `.run` and `.fireAndForget`
34- /// functions on ``EffectTask``, then threading is automatically handled for you.
6+ /// This type is deprecated in favor of ``EffectTask``. See its documentation for more information.
7+ @available (
8+ iOS,
9+ deprecated: 9999.0 ,
10+ message:
11+ """
12+ 'EffectPublisher' has been deprecated in favor of 'EffectTask'.
13+
14+ You are encouraged to use `EffectTask<Action>` to model the ouput of your reducers, and to use Swift concurrency to model asynchrony in dependencies.
15+
16+ See the migration roadmap for more information: https://github.com/pointfreeco/swift-composable-architecture/discussions/1477
17+ """
18+ )
19+ @available (
20+ macOS,
21+ deprecated: 9999.0 ,
22+ message:
23+ """
24+ 'EffectPublisher' has been deprecated in favor of 'EffectTask'.
25+
26+ You are encouraged to use `EffectTask<Action>` to model the ouput of your reducers, and to use Swift concurrency to model asynchrony in dependencies.
27+
28+ See the migration roadmap for more information: https://github.com/pointfreeco/swift-composable-architecture/discussions/1477
29+ """
30+ )
31+ @available (
32+ tvOS,
33+ deprecated: 9999.0 ,
34+ message:
35+ """
36+ 'EffectPublisher' has been deprecated in favor of 'EffectTask'.
37+
38+ You are encouraged to use `EffectTask<Action>` to model the ouput of your reducers, and to use Swift concurrency to model asynchrony in dependencies.
39+
40+ See the migration roadmap for more information: https://github.com/pointfreeco/swift-composable-architecture/discussions/1477
41+ """
42+ )
43+ @available (
44+ watchOS,
45+ deprecated: 9999.0 ,
46+ message:
47+ """
48+ 'EffectPublisher' has been deprecated in favor of 'EffectTask'.
49+
50+ You are encouraged to use `EffectTask<Action>` to model the ouput of your reducers, and to use Swift concurrency to model asynchrony in dependencies.
51+
52+ See the migration roadmap for more information: https://github.com/pointfreeco/swift-composable-architecture/discussions/1477
53+ """
54+ )
3555public struct EffectPublisher < Action, Failure: Error > {
3656 @usableFromInline
3757 enum Operation {
@@ -60,20 +80,38 @@ extension EffectPublisher {
6080 }
6181}
6282
63- /// A convenience type alias for referring to an effect that can never fail, like the kind of
64- /// ``EffectPublisher`` returned by a reducer after processing an action .
83+ /// A type that encapsulates a unit of work that can be run in the outside world, and can feed
84+ /// actions back to the ``Store`` .
6585///
66- /// Instead of specifying `Never` as `Failure`:
86+ /// Effects are the perfect place to do side effects, such as network requests, saving/loading
87+ /// from disk, creating timers, interacting with dependencies, and more. They are returned from
88+ /// reducers so that the ``Store`` can perform the effects after the reducer is done running.
6789///
68- /// ```swift
69- /// func reduce(into state: inout State, action: Action) -> EffectPublisher<Action, Never> { … }
70- /// ```
90+ /// There are 2 distinct ways to create an `Effect`: one using Swift's native concurrency tools, and
91+ /// the other using Apple's Combine framework:
7192///
72- /// You can specify a single generic:
93+ /// * If using Swift's native structured concurrency tools then there are 3 main ways to create an
94+ /// effect, depending on if you want to emit one single action back into the system, or any number
95+ /// of actions, or just execute some work without emitting any actions:
96+ /// * ``EffectPublisher/task(priority:operation:catch:file:fileID:line:)``
97+ /// * ``EffectPublisher/run(priority:operation:catch:file:fileID:line:)``
98+ /// * ``EffectPublisher/fireAndForget(priority:_:)``
99+ /// * If using Combine in your application, in particular for the dependencies of your feature
100+ /// then you can create effects by making use of any of Combine's operators, and then erasing the
101+ /// publisher type to ``EffectPublisher`` with either `eraseToEffect` or `catchToEffect`. Note that
102+ /// the Combine interface to ``EffectPublisher`` is considered soft deprecated, and you should
103+ /// eventually port to Swift's native concurrency tools.
73104///
74- /// ```swift
75- /// func reduce(into state: inout State, action: Action) -> EffectTask<Action> { … }
76- /// ```
105+ /// > Important: The publisher interface to ``EffectTask`` is considered deperecated, and you should
106+ /// try converting any uses of that interface to Swift's native concurrency tools.
107+ /// >
108+ /// > Also, ``Store`` is not thread safe, and so all effects must receive values on the same
109+ /// thread. This is typically the main thread, **and** if the store is being used to drive UI then
110+ /// it must receive values on the main thread.
111+ /// >
112+ /// > This is only an issue if using the Combine interface of ``EffectPublisher`` as mentioned
113+ /// above. If you are using Swift's concurrency tools and the `.task`, `.run` and `.fireAndForget`
114+ /// functions on ``EffectTask``, then threading is automatically handled for you.
77115public typealias EffectTask < Action> = Effect < Action , Never >
78116
79117extension EffectPublisher where Failure == Never {
@@ -609,57 +647,20 @@ extension EffectPublisher {
609647}
610648
611649@available (
612- iOS,
613- deprecated: 9999.0 ,
650+ * ,
614651 message:
615652 """
616- 'Effect' has been deprecated in favor of 'EffectTask' when `Failure == Never`, or
617- `EffectPublisher<Output, Failure>` in general.
653+ 'Effect' has been deprecated in favor of 'EffectTask' when 'Failure == Never', or 'EffectPublisher<Output, Failure>' in general.
618654
619- You are encouraged to use `EffectTask<Action>` to model the ouput of your reducers, and to Swift
620- concurrency to model failable streams of values.
655+ You are encouraged to use 'EffectTask<Action>' to model the output of your reducers, and to use Swift concurrency to model failable streams of values.
621656
622- See the migration roadmap for more information: https://github.com/pointfreeco/swift-composable-architecture/discussions/1477
623- """
624- )
625- @available (
626- macOS,
627- deprecated: 9999.0 ,
628- message:
629- """
630- 'Effect' has been deprecated in favor of 'EffectTask' when `Failure == Never`, or
631- `EffectPublisher<Output, Failure>` in general.
632-
633- You are encouraged to use `EffectTask<Action>` to model the ouput of your reducers, and to Swift
634- concurrency to model failable streams of values.
657+ To find and replace instances of 'Effect<Action, Never>' to 'EffectTask<Action, Never>' in your codebase, use the following regular expression:
635658
636- See the migration roadmap for more information: https://github.com/pointfreeco/swift-composable-architecture/discussions/1477
637- """
638- )
639- @available (
640- tvOS,
641- deprecated: 9999.0 ,
642- message:
643- """
644- 'Effect' has been deprecated in favor of 'EffectTask' when `Failure == Never`, or
645- `EffectPublisher<Output, Failure>` in general.
646-
647- You are encouraged to use `EffectTask<Action>` to model the ouput of your reducers, and to Swift
648- concurrency to model failable streams of values.
659+ Find:
660+ Effect<([^,]+), Never>
649661
650- See the migration roadmap for more information: https://github.com/pointfreeco/swift-composable-architecture/discussions/1477
651- """
652- )
653- @available (
654- watchOS,
655- deprecated: 9999.0 ,
656- message:
657- """
658- 'Effect' has been deprecated in favor of 'EffectTask' when `Failure == Never`, or
659- `EffectPublisher<Output, Failure>` in general.
660-
661- You are encouraged to use `EffectTask<Action>` to model the ouput of your reducers, and to Swift
662- concurrency to model failable streams of values.
662+ Replace:
663+ EffectTask<$1>
663664
664665 See the migration roadmap for more information: https://github.com/pointfreeco/swift-composable-architecture/discussions/1477
665666 """
0 commit comments