rxSwift Flashcards
What is side effects?
Side effects are any change to the state outside of the current scope.
What is Imperative programming?
Imperative programming is a programming paradigm that uses statements to change the program’s state.
Core issues that rxSwift dealt with
Shared mutable data
The order in which pieces of work are performed
“RxSwift finds the sweet spot between traditionally imperative Cocoa code and purist functional code. It allows you to react to events by using immutable code definitions to process asynchronously pieces of input in a deterministic, composable way.”
What is Subject in RxSwift
Observable and Observer
Publish/Behaviour/Replay
Replay:
To kill cache you have to call dispose
“buffer is held in memory.”
What subject do after termination?
Every subject type, once terminated, will re-emit its stop event to future subscribers
Creating observable factories
Observable.deferred { }
Explain Observables
“Carry” an immutable piece of data Observable
Traits
Single
Maybe
Completable
Events
Next
Completed
Error
an observable won’t send events until it has a subscriber. Remember that an observable is really a sequence definition
Filtering operators -> Ignoring operators
ignoreElements()
elementAt(1)
filter { $0 > 3 }
Filtering operators -> skiping operators
skip(2)
skipWhile { $0 % 2 == 1}
skipUntil - hasTrigger
Filtering operators -> taking operators
takeWhile { $0 < 3 }
take(2)
takeUntil - has trigger
elementAt(1)
Filtering operators -> Distinct operators
DistinctUntilChanged {$0 $1}
Filtering operators -> Transforming operators
toArray map -> can be .enumerated() flatMap flatMapLatest Materialize Dematerialise
Explain flatMap and flatMapLatest
Add async and project observable
Combining operators
Combining operators Start with concat: sequential processing. concat concatMap merge: Just one event from observable that sends it event (can be many observables ) cobineLatest: Combine events from observables and sends it together triggers withLatestFrom sample switches amb SwitchLatest reduce scan
Timing operators
Timing operators Replaying past elements: You should call .connect() to start ReplayAll .replay(amount) Controlled buffering -> The only difference is that it emits an Observable of the buffered items, instead of emitting an array. .buffer(timeSpan:count:scheduler:) Windows of buffered observables .window(timeSpan:, count:, scheduler:) Time-shifting operators Delayed elements Delayed subscription Timer operators Intervals One-shot or repeating timers Timeouts
.take(5.0, scheduler: MainScheduler.instance)
.throttle(0.5, scheduler: MainScheduler.instance)