Improves `Tips.md`.

This commit is contained in:
Krunoslav Zaher 2016-03-12 20:30:09 +01:00
parent c3707616c0
commit c6a1f799b0
1 changed files with 29 additions and 1 deletions

View File

@ -19,4 +19,32 @@ extension ObservableType where E: MaybeCool {
}
```
* Rx operators are as general as possible, but there will always be edge cases that will be hard to model. In those cases
* Rx operators are as general as possible, but there will always be edge cases that will be hard to model. In those cases you can just create your own operator and possibly use one of the built-in operators as a reference.
* Always use operators to compose subscriptions.
**Avoid nesting subscribe calls at all cost. This is a bad smell.**
```swift
textField.rx_text.subscribeNext { text in
performURLRequest(text).subscribeNext { result in
...
}
.addDisposableTo(disposeBag)
}
.addDisposableTo(disposeBag)
```
**Preferred way of chaining disposables by using operators.**
```swift
textField.rx_text
.flatMapLatest { text in
// Assuming this doesn't fail and returns result on main scheduler,
// otherwise `catchError` and `observeOn(MainScheduler.instance)` can be used to
// correct this.
return performURLRequest(text)
}
...
.addDisposableTo(disposeBag) // only one top most disposable
```