diff --git a/Documentation/Tips.md b/Documentation/Tips.md index eeb52a31..927687a8 100644 --- a/Documentation/Tips.md +++ b/Documentation/Tips.md @@ -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 + ```