반응형프로그래밍입문 2회 20161010
TRANSCRIPT
유동환
반응형프로그래밍입문 (2회)
1 2016.10.10
오늘의주제
1. Observables로 시작하기
2. Cold vs Hot Observables 차이점
3. Operators 살펴보기
2
#1 Observables
3
데이터의 시작
무엇을 Observables로 할 수 있을까?
각종 자료구조: 문자열, 배열, List 등
사용자 입력
서버의 리턴값 (JSON 등)
그 외 데이터의 시작
#1 Observable.just()
4출처: https://github.com/meddle0x53/learning-rxjava,CreatingObservablesWithFrom.java
단일(다수) 객체에서 가져오기
Observable.just() 호출
#1 Observable.from()
5출처: https://github.com/meddle0x53/learning-rxjava,CreatingObservablesWithFrom.java
List, 배열에서 가져오기
Observable.from() 호출
#1 Observable.from()
6출처: https://github.com/meddle0x53/learning-rxjava,CreatingObservablesWithFrom.java
Iterable<T>에서 가져오기
참고) Java7의 try-with-resource 구문
#2 Cold vs. Hot Observables
7
Cold Observables는 Subscriber가 구독하면 Producer가 새로 생성됨. 데이터도 그때 발생함. (지금까지의 예제)
So let’s replace 1 with Date.now() and see what happens.
출처: http://blog.thoughtram.io/angular/2016/06/16/cold-vs-hot-observables.html
#2 Cold vs. Hot Observables
8
차이점 비교
출처: https://medium.com/@benlesh/hot-vs-cold-observables-f8094ed53339#.o0iqkxicw
#2 Cold vs. Hot Observables
9
Hot Observables는 구독자가 없어도 data를 발생시킴
매번 새로 생성할 수 없는 Observable은 Hot 해야한다!
출처: http://www.introtorx.com/content/v1.0.10621.0/14_HotAndColdObservables.html
출처: https://medium.com/@benlesh/hot-vs-cold-observables-f8094ed53339#.o0iqkxicw
#2 Cold vs. Hot Observables
10
Cold를 Hot으로 만드는 방법
1. ConnectableObservable을 사용
2. Subject를 사용
>ConnectableObservable은connect하면 그때부터 data를 발생시킴
>Subject에는
1. PublishSubject
2. BehaviorSubject
3. ReplaySubject
4. AsyncSubject 가 있음
출처: http://www.introtorx.com/content/v1.0.10621.0/14_HotAndColdObservables.html
#2 ConnectableObservable
11출처: https://github.com/meddle0x53/learning-rxjava, UsingConnectableObservables.java
//connect 한 이후에 data가 발생함
#2 ConnectableObservable:: publish()
12출처: http://reactivex.io/documentation/operators/publish.html
#2 ConnectableObservable
13출처: https://github.com/meddle0x53/learning-rxjava, UsingConnectableObservables.java
#2 ConnectableObservable:: share()
14출처: http://reactivex.io/documentation/operators/publish.html
#3-1 Map
15출처: http://reactivex.io/documentation/operators/map.html
#3-1 Map
16
출처: https://github.com/meddle0x53/learning-rxjava, MappingExamples.java
#3-2 FlatMap
17출처: http://reactivex.io/documentation/operators/flatmap.html
#3-2 FlatMap
18
출처: https://github.com/meddle0x53/learning-rxjava, FlatMapAndFiles.java
#3-3 Filter
19출처: http://reactivex.io/documentation/operators/filter.html
#3-3 Filter
20
출처: https://github.com/meddle0x53/learning-rxjava, FilteringExamples.java
마치며
21
3회에는 Subject와 다른 Operators에 대해서
알아보겠습니다.