상세 컨텐츠

본문 제목

RxSwift. Ch 6. Filtering Operators in Practice.

TIL/RxSwift

by box-jeon 2020. 4. 25. 23:54

본문

이전 챕터에서 실습한 Combinestagram을 이어갑니다. 최근에 '아 이래서 내가 Rx를 못 따라가고 있는 모양이구나' 생각하게 만든 문장이 튀어나왔습니다.

Observables are lazy, pull-driven sequence. Simply calling a bunch of operators on an Observable doesn't involve any actual work. The moment you call subscribe(...) directly on an observable or on one of the operators applied to it, that's when the Observable livens up and starts producing elements.

Hot Observable을 Notification으로 생각하면서 그동안 작업을 해왔었는데... Observable.create 내부에 로직을 어디까지 포함시켜야하는지 아직 좀 혼란스럽습니다. 여튼, Observable을 Notification처럼 다루려고 한다면 share()가 필수입니다.

public func share(replay: Int = 0, scope: SubjectLifetimeScope = .whileConnected)

        -> Observable<Element>

Trying out time-based filter operators

  • take(_ duration: RxTimeInterval, scheduler: SchedulerType) - duration이 지날 때까지 .next 이벤트를 전달합니다. 전달 직후, .completed 이벤트를 방출합니다.
  • throttle(_ dueTime: RxTimeInterval, latest: Bool = true, scheduler: SchedulerType) - .next 이벤트 발생 후, duTime 이내에 새로운 .next 이벤트가 발생할 경우, 이전 이벤트를 무시합니다. Dynamic search 상황에서 사용됩니다.

관련글 더보기

댓글 영역