Skip to content

Commit 58d92aa

Browse files
authored
Add Rx migration cheatsheet (#793)
1 parent f037139 commit 58d92aa

File tree

2 files changed

+124
-3
lines changed

2 files changed

+124
-3
lines changed

Documentation/RxCheatsheet.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# RxSwift to ReactiveSwift Cheatsheet
2+
This is a Cheatsheet for [RxSwift](https://github.com/ReactiveX/RxSwift) developers migrating to projects using [ReactiveSwift](https://github.com/ReactiveCocoa/ReactiveSwift).
3+
4+
Inspired by the [RxSwift to Combine cheatsheet](https://github.com/CombineCommunity/rxswift-to-combine-cheatsheet)
5+
6+
## Basics
7+
8+
| | RxSwift | ReactiveSwift |
9+
|-----------------------|----------------------------------|--------------------------------------------|
10+
| Deployment Target | iOS 8.0+ | iOS 8.0+
11+
| Platforms supported | iOS, macOS, tvOS, watchOS, Linux | iOS, macOS, tvOS, watchOS, Linux
12+
| Spec | Reactive Extensions (ReactiveX) | Originally ReactiveX, with significant divergence
13+
| Framework Consumption | Third-party | Third-party
14+
| Maintained by | Open-Source / Community | Open-Source / Community
15+
| UI Bindings | RxCocoa | ReactiveCocoa
16+
17+
18+
## Core Components
19+
20+
| RxSwift | ReactiveSwift | Notes |
21+
|---------------------------|---------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
22+
| AnyObserver | Signal.Observer | In practice, since there are no different Observer types, the AnyObserver concept is redundant in ReactiveSwift
23+
| BehaviorRelay | Property / MutableProperty | Since `MutableProperty` can never have errors, we don't need a Relay specific version.
24+
| BehaviorSubject | Property / MutableProperty |
25+
| Completable | Signal / SignalProducer | A `Signal` or `SignalProducer` where `Value == Never` can only complete or emit an error event
26+
| CompositeDisposable | CompositeDisposable |
27+
| ConnectableObservableType ||
28+
| Disposable | Disposable | In ReactiveSwift you rarely have to keep hold of Disposables or manage their lifetime manually, it's mostly automatic.
29+
| DisposeBag | CompositeDisposable | The concepte of a DisposeBag is not really needed in ReactiveSwift, see above.
30+
| Driver ||
31+
| Maybe | ❌ | Trivial to create using `take(first: 1)`
32+
| Observable | Signal / SignalProducer | Signal is a "hot" observable, and SignalProducer is a "cold" observable that will only emit values once a subscription is started
33+
| Observer | Signal.Observer |
34+
| PublishRelay | ❌ | Could be recreated easily in ReactiveSwift using the `flatMapError` operator on a Signal.pipe()
35+
| PublishSubject | Signal.pipe() | There is no Subject type, but `Signal.pipe()` returns a tuple of `(output: Signal, input: Signal.Observer)` which you use to both observe and send values
36+
| ReplaySubject | ❌ | Can be created using the `replayLazily(upTo:)` operator
37+
| ScheduledDisposable ||
38+
| SchedulerType | Scheduler |
39+
| SerialDisposable | SerialDisposable |
40+
| Signal | ❌ | Not to be confused with ReactiveSwift `Signal` which is completely different
41+
| Single | ❌ | Could easily be created as an initializer for `SignalProducer`
42+
| SubjectType | Signal.pipe() | There is no Subject type, but `Signal.pipe()` returns a tuple of `(output: Signal, input: Signal.Observer)` which you use to both observe and send values
43+
| TestScheduler | TestScheduler |
44+
45+
46+
## Operators
47+
48+
| RxSwift | Combine | Notes |
49+
|-----------------------|------------------------------------------|----------------------------------------------------------------------------------------------------------|
50+
| amb() | flatten(.race) |
51+
| asObservable() | ❌ | Not required in ReactiveSwift, although `Property.producer` and `Property.signal` are similar
52+
| asObserver() ||
53+
| bind(to:) | <~ operator (BindingTargets) |
54+
| buffer | ❌ | (it used to exist, but was removed)
55+
| catchError | flatMapError |
56+
| catchErrorJustReturn | ❌ | Easy to create as `flatMapError { _ in SignalProducer<Value, Never> (value: value) }`
57+
| combineLatest | combineLatest |
58+
| compactMap | compactMap |
59+
| concat | concat / prefix |
60+
| concatMap ||
61+
| create | SignalProducer.init { } |
62+
| debounce | debounce |
63+
| debug | logEvents |
64+
| deferred | ❌ | Trivial to create
65+
| delay | delay |
66+
| delaySubscription ||
67+
| dematerialize | dematerialize |
68+
| distinctUntilChanged | skipRepeats |
69+
| do | on |
70+
| elementAt ||
71+
| empty | SignalProducer.empty |
72+
| enumerated ||
73+
| error | SignalProducer.init(error:) |
74+
| filter | filter |
75+
| first | take(first:) | See also `take(last:)`
76+
| flatMap | flatMap(.merge) |
77+
| flatMapFirst | flatMap(.throttle) |
78+
| flatMapLatest | flatMap(.latest) |
79+
| from(optional:) | ❌ | Easy to create using `.init(.value: Value?).skipNil()`
80+
| groupBy ||
81+
| ifEmpty(default:) ||
82+
| ifEmpty(switchTo:) ||
83+
| ignoreElements | ❌ | Easy to create
84+
| interval ||
85+
| just | SignalProducer.init(value:) |
86+
| map | map |
87+
| materialize | materialize |
88+
| merge | merge |
89+
| merge(maxConcurrent:) ||
90+
| multicast | replayLazily(upTo:) |
91+
| never | SignalProducer.never |
92+
| observeOn | observe(on:) |
93+
| of | SignalProducer.init(_ values:) |
94+
| publish ||
95+
| range ||
96+
| reduce | reduce |
97+
| refCount | ❌ | Not meaningful in ReactiveSwift
98+
| repeatElement | repeat |
99+
| retry, retry(3) | retry(upTo:) |
100+
| retryWhen ||
101+
| sample | sample(on:), sample(with:) |
102+
| scan | scan |
103+
| share | replayLazily(upTo:) |
104+
| skip | skip(first:) |
105+
| skipUntil | skip(until:) |
106+
| skipWhile | skip(while:) |
107+
| startWith | prefix |
108+
| subscribe | startWithValues / observeValues |
109+
| subscribeOn | start(on:) / observe(on:) |
110+
| takeLast | take(last:) |
111+
| takeUntil | take(until:) |
112+
| throttle | throttle |
113+
| timeout | timeout |
114+
| timer | SignalProducer.timer |
115+
| toArray | collect |
116+
| window ||
117+
| withLatestFrom | combineLatest |
118+
| zip | zip |

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Learn about the **[Core Reactive Primitives][]** in ReactiveSwift, and **[Basic Operators][]** available offered by these primitives.
1515

1616
### Extended modules
17-
17+
1818
<table>
1919
<tr>
2020
<th>Module</th>
@@ -48,7 +48,7 @@ Learn about the **[Core Reactive Primitives][]** in ReactiveSwift, and **[Basic
4848
</td>
4949
<td><p>The <a href="https://github.com/pointfreeco/swift-composable-architecture">Pointfree Composable Architecture</a> using ReactiveSwift instead of Combine.</p></td>
5050
</tr>
51-
</table>
51+
</table>
5252

5353
## What is ReactiveSwift in a nutshell?
5454
__ReactiveSwift__ offers composable, declarative and flexible primitives that are built around the grand concept of ___streams of values over time___.
@@ -69,6 +69,8 @@ code and state to bridge the gap.
6969

7070
1. **[Debugging Techniques][]**
7171

72+
1. **[RxSwift Migration Cheatsheet][]**
73+
7274
## Installation
7375

7476
ReactiveSwift supports macOS 10.9+, iOS 8.0+, watchOS 2.0+, tvOS 9.0+ and Linux.
@@ -120,7 +122,7 @@ We also provide a Playground, so you can get used to ReactiveCocoa's operators.
120122

121123
1. Clone the ReactiveSwift repository.
122124
1. Retrieve the project dependencies using one of the following terminal commands from the ReactiveSwift project root directory:
123-
- `git submodule update --init --recursive` **OR**, if you have [Carthage][] installed
125+
- `git submodule update --init --recursive` **OR**, if you have [Carthage][] installed
124126
- `carthage checkout`
125127
1. Open `ReactiveSwift.xcworkspace`
126128
1. Build `ReactiveSwift-macOS` scheme
@@ -143,6 +145,7 @@ ReactiveSwift has no plan to declare ABI and module stability at the moment. It
143145
[API Contracts]: Documentation/APIContracts.md
144146
[API Reference]: http://reactivecocoa.io/reactiveswift/docs/latest/
145147
[Debugging Techniques]: Documentation/DebuggingTechniques.md
148+
[RxSwift Migration Cheatsheet]: Documentation/RxCheatsheet.md
146149
[Online Searching]: Documentation/Example.OnlineSearch.md
147150
[_UI Examples_ playground]: https://github.com/ReactiveCocoa/ReactiveSwift/blob/master/ReactiveSwift-UIExamples.playground/Pages/ValidatingProperty.xcplaygroundpage/Contents.swift
148151

0 commit comments

Comments
 (0)