SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
Observable c++ expressions using the observable library 이근원
Observable c++ expressions using the observable library 이근원
1.
Observable C++ expressions
using
Observable Library
-
NHN NEXT 이근원
2.
Index
1. Observable C++ Expression
2. Observable Library
1. Features & Setting
2. Using Subject
3. Using Value
4. Using Property
3.
Observable C++ Expression
- With Average Example
일반적으로 우리가 두 수의 평균을 구하는 방법.
값이 바뀌면 다시 평균을 계산한다.
요걸 Observable library를 사용하면...
값이 얼마가 변하던 다시 계산해줄 필요가 없다!
구독 메소드를 이용해 코드를 reactive하게 만들 수 있다.
-> Observable 라이브러리를 사용해 볼까?
4.
Observable Library
- Feature
github : https://github.com/ddinu/observable
- Header-Only 라이브러리라 사용하기 쉽다.
- MSVC15 (VS 2017), GCC 5.4, 6.2, Clang 3.6~3.9 지원
- 손쉽게 Reactive Programming이나 Observer pattern을 구현할 수 있다.
5.
Observable Library
- Setting
다들 아시겠지만~~ 사용법
- Observable 라이브러리의 Github에서 다운로드.
- Header Only 라이브러리기 때문에
디렉토리 설정만 해주면 된다.
7.
Library Examples
- With Subject
subject<T> 클래스 생성.
- 인자로 받은 형태를 내부에 std::function 형태로 저장.
- 내부 저장소는 Thread-safe 하지만
함수 호출 순서는 특정할 수 없음.
관심 있는 주제에 대해 구독.
- Subscribe : Subscribe 오브젝트를 반환.
- 오브젝트는 Unsubscribe를 위해 보관.
- 혹은 Release를 호출하여 분리할 수 있음.
이름을 입력 받고 Notify 메소드로 전파.
8.
Library Examples
- With Values
value<T> 클래스 생성.
- 새로운 값이 들어올 때마다 std::equal_to<T>를 이용해 검사
- EqualityComparable하지 않다면 같지 않은 것으로 분류.
- 새 값이 기존 값과 같지 않다면(변화되었다면) Notify
관심 있는 값에 대해 Observe
- 이름이 변경될 때마다 구독된 함수 호출
9.
Library Examples
- With Properties
Observable_property 선언.
- 기본적으로는 value<T>와 같음.
호출할 함수 구현.
- 이것 역시 앞 예제와 같음.
10.
출처
-
Observable Library : https://github.com/ddinu/observable
Post : https://danieldinu.com/posts/observable-cpp-library/