際際滷

際際滷Share a Scribd company logo
? ????? ????
?? ?? Rx ???
???, NAVER ?????? 3.0
http://huns.me
???? ??? ?? ????? ???? ? ???
Observable ??? ?? ?????
Rx
2005 ??
2007,
Volta
2009,
RX.NET
2010,
RXJS
2012,
???? ??
2013
RxJava
^Of all the work I¨ve done in my career so far, this is
the most exciting. [´] I know it¨s a bold statement,
but I really believe that the problem of
asynchronous programming events has been
solved. ̄
https://campustechnology.com/articles/2009/08/10/microsofts-new-.net-rx-
framework-tackles-challenges-of-asynchronous-programming.aspx
??
1. Rx? ???? ? ?? ???
2. ?? ?? ? ?? ????
3. ??? ???? ?????
4. ? ?????, ??? RxJS
#1
Rx? ????
? ?? ???
Reactive Programming
LINQ to Events
Scheduler
Reactive
Programming
??? ???? ?? ??? ?????
??? ??? ? ????? ????
Reactive Programming in Wikipedia, The Free Encyclopedia
Reactive systems [´] are repeatedly prompted
by the outside world and their role is to
continusouly respond
external inputs
- On the development of reactive systems, 1985 -
http://dl.acm.org/citation.cfm?id=101990
??? ??? ??? ??
??? ???? ???? ???
??
??? ???????????? ????????? ????? ?????? Rx ??????
Iterator Data
next()
Observer Data
subscribe()
?? ?? ?? ???? ??? ?? ??? ??. ?? 1:1? ?
??? ?? xi? yi(i1, 2, ´)? ???? ?? S1{x1,
x2, ´}, S2{y1, y2, ´} ?? ??? ??. ??? S1? S2? ?
???? ?? ???? ???. S1? ??? ?? r(x1, x2, ´,
xn)? ??? ? ? ??? ??? ? xi? ???? yi? ???
?? P(y1, y2, ´, yn)? S2? ??? ????. S1, S2 ?? ??
?? ?? ?? ??? ??? ????? ?? xi, yi? ??? ?
? r(x1, x2, ´), P(y1, y2, ´)? ?? ??? ??. ?? ????
? ?? ?? ??? ??? ???? ???? ????.
[??? ????] ??? [duality] (IT????, ??????????)
??? ???????????? ????????? ????? ?????? Rx ??????
A? B? ??? ??
(??? ?? ??)
?? ?? ?? ???? ??? ??
??? ??. ?? 1:1? ???? ?
? xi? yi(i1, 2, ´)? ???? ??
S1{x1, x2, ´}, S2{y1, y2, ´} ?
? ??? ??. ??? S1? S2? ?
???? ?? ???? ???. S1?
??? ?? r(x1, x2, ´, xn)? ???
? ? ??? ??? ? xi? ????
yi? ??? ?? P(y1, y2, ´, yn)? S2
? ??? ????. S1, S2 ?? ??
?? ?? ?? ??? ??? ???
?? ?? xi, yi? ??? ?? r(x1,
x2, ´), P(y1, y2, ´)? ?? ??? ?
?. ?? ????? ?? ?? ???
??? ???? ???? ????.
event
Iterable
(pull)
Observable
(push)
??? ???? T next() next(T)
?? ?? throws Exception error(Exception)
?? !hasNext() complete()
LINQ to Events
???? LINQ? ??? ???
?????(Operator) ??
Language
INtergrated
Query
?? ???? ?? ?? ?? ??
C# 3.0?? ??
??? ?? ?? ??
//Query syntax:?
IEnumerable<int> numQuery1 =?
from num in numbers?
where num % 2 == 0?
orderby num?
select num;?
?
//Method syntax:?
IEnumerable<int> numQuery2 = numbers?
.Where(num => num % 2 == 0)?
.OrderBy(n => n);
//Query syntax:?
IEnumerable<int> numQuery1 =?
from num in numbers?
where num % 2 == 0?
orderby num?
select num;?
?
//Method syntax:?
IEnumerable<int> numQuery2 = numbers?
.Where(num => num % 2 == 0)?
.OrderBy(n => n);
Your Mouse is
a DataBase
= Observable + LINQ
??? ???????????? ????????? ????? ?????? Rx ??????
Mouse Move
Event
const targetElement = document.getElementById('dragElement');?
const drag$ = Rx.Observable?
.fromEvent(targetElement, 'mouseup');?
?
drag$?
.flatMap(ev => ({?
startX: ev.pageX,?
startY: ev.pageY?
}));?
?
drag$.subscribe(pos => {?
console.log(pos);?
});
Mouse Move
Event
const targetElement = document.getElementById('dragElement');?
const drag$ = Rx.Observable?
.fromEvent(targetElement, 'mouseup');?
?
drag$?
.flatMap(ev => ({?
startX: ev.pageX,?
startY: ev.pageY?
}));?
?
drag$.subscribe(pos => {?
console.log(pos);?
});
Subscribe
const targetElement = document.getElementById('dragElement');?
const drag$ = Rx.Observable?
.fromEvent(targetElement, 'mouseup');?
?
drag$?
.flatMap(ev => ({?
startX: ev.pageX,?
startY: ev.pageY?
}));?
?
drag$.subscribe(pos => {?
console.log(pos);?
});
Scheduler
???(?????) ????
????? ?? ?? ??
??? ???????????? ????????? ????? ?????? Rx ??????
#2
?? ??,
? ?? ????
Rx? ?? ?? ???
? ?? Rx?
??? ???????????? ????????? ????? ?????? Rx ??????
??? ???????????? ????????? ????? ?????? Rx ??????
https://medium.com/reactive-programming/what-is-reactive-programming-bc9fa7f4a7fc#.ddo2ci9wx
Reactive Manifesto
http://www.reactivemanifesto.org/
Responsive
Reactive Manifesto
http://www.reactivemanifesto.org/
Responsive
Elastic Resilient
Reactive Manifesto
http://www.reactivemanifesto.org/
Responsive
Resilient
Message-Driven
Elastic
callback
promise
generator
async/await
´
(Compositionality)
???
??? ??? ?? ??
?? / ? / ? / ?? / ?? / ??
?? / ? / ?-/ ? / ?? / ?? / ?- / ?- / ?
??? ???????????? ????????? ????? ?????? Rx ??????
??? ???????????? ????????? ????? ?????? Rx ??????
??? ???????????? ????????? ????? ?????? Rx ??????
??? ???????????? ????????? ????? ?????? Rx ??????
1
2
3
http://labs.bench.co/blog/2014/12/10/microservices-at-bench-intro
https://www.kirupa.com/react/components.htm
Functional + Rx
?? -> ?? -> ??
??? ???
??? ???????????? ????????? ????? ?????? Rx ??????
sum = a + b
sum = a + b
a? b? ?? sum? ???
sum = a + b
???, ?? ??
a
b
sum
const a = document.getElementById('a');?
const a$ = Rx.Observable?
.fromEvent(a, 'keyup')?
.map(e => parseInt(e.target.value || 0, 10))?
.startWith(parseInt(a.value, 10));?
const b = document.getElementById('b');?
const b$ = Rx.Observable?
.fromEvent(b, 'keyup')?
.map(e => parseInt(e.target.value || 0, 10))?
.startWith(parseInt(b.value, 10));?
?
const result$ = Rx.Observable?
.combineLatest(a$, b$)?
.map(values => values.reduce((acc, cur) => acc + cur));?
?
result$.subscribe(res => document.getElementById('result').value = res);
a
const a = document.getElementById('a');?
const a$ = Rx.Observable?
.fromEvent(a, 'keyup')?
.map(e => parseInt(e.target.value || 0, 10))?
.startWith(parseInt(a.value, 10));?
const b = document.getElementById('b');?
const b$ = Rx.Observable?
.fromEvent(b, 'keyup')?
.map(e => parseInt(e.target.value || 0, 10))?
.startWith(parseInt(b.value, 10));
?
?
const result$ = Rx.Observable?
.combineLatest(a$, b$)?
.map(values => values.reduce((acc, cur) => acc + cur));?
?
result$.subscribe(res => document.getElementById('result').value = res);
a
b
const a = document.getElementById('a');?
const a$ = Rx.Observable?
.fromEvent(a, 'keyup')?
.map(e => parseInt(e.target.value || 0, 10))?
.startWith(parseInt(a.value, 10));
const b = document.getElementById('b');?
const b$ = Rx.Observable?
.fromEvent(b, 'keyup')?
.map(e => parseInt(e.target.value || 0, 10))?
.startWith(parseInt(b.value, 10));
const sum$ = Rx.Observable?
.combineLatest(a$, b$)?
.map(values => values.reduce((acc, cur) => acc + cur));?
?
sum$.subscribe(res => document.getElementById('result').value = res);
a
b
sum
#3
???
????
?????(FRP)
??? ???? ?????(FRP)?
??? ??? ??
It is sometimes called ^functional reactive
programming ̄ but this is a misnomer.
ReactiveX may be functional, and it may be
reactive, but ^functional reactive
programming ̄ is a different animal.
http://reactivex.io/intro.html
??? ???????????? ????????? ????? ?????? Rx ??????
Functional
Reactive
AnimatioN
by Conal Elliott and Paul Hudak, 1997
????? 3D ??? ??
??? ???? ??
??? ?? ??? ?? ??(Behavior)
??? ???? ?????(FRP)? ??
http://images.slideplayer.com/26/8448601/slides/slide_4.jpg
??? ???????????? ????????? ????? ?????? Rx ??????
wiggle = sin(pi * time)
wiggle = sin(pi * time)
Behavior
moveXY(x, y, image)
moveXY wiggle 0 image
charlotte = importBitmap "../Media/charlotte.bmp"
moveXY wiggle 0 charlotte
http://conal.net/fran/tutorial.htm
leftRightCharlotte = moveXY wiggle 0 charlotte
upDownPat = moveXY 0 waggle pat
charlottePatDance = leftRightCharlotte `over` upDownPat
https://prezi.com/rfgd0rzyiqp_/controlling-time-and-space/
"Original FRP" refers to
denotational and
continuous-time
functional programming
using behaviors
and events.
https://github.com/conal/talk-2015-essence-and-origins-of-frp
https://medium.com/@andrestaltz/why-i-cannot-say-frp-but-i-just-did-d5ffaa23973b#.xtc4pmnco
const result$ = Rx.Observable?
.combineLatest(a$, b$)?
.map(values => {
values.reduce((acc, cur) => acc + cur)
});
??? ?(descret value) ??!
??? ??? ??? ??? ??!
???(compositionality) ??!
ones 1 2
hundreds 200
sum 101 202
??
100
ones 1 2
hundreds 200
sum 101 202
??
100
ones 1 2
hundreds 200
sum 101 202
??
102
?? ???(glitch)
100
??? ???????????? ????????? ????? ?????? Rx ??????
Rx = ??? - ??
Rx? ???? ???????
???? ???? ???? ??? ??
http://csl.stanford.edu/~christos/pldi2010.fit/meijer.duality.pdf
event
Iterable
(pull)
Observable
(push)
??? ???? T next() next(T)
?? ?? throws Exception error(Exception)
?? !hasNext() complete()
None BlockingBlocking
#4
? ?????,
??? RxJS
? ??????? RxJS? ?? ??? ????
??? ??, OOP ??
KVO(Key-Value Observing)
??? ??? ???
??? ????
?? DOM? ??? ???
?? ??? ?? ????
?? ?? ??
??? ??? ???
??? ? ?? ?? ??
?? ??
MVI(Model-View-Intent)
?? ??? ??
??? ?????
+ Reactive
+ Functional
OOP FP
Angular2´?
OOP FP
2
But,
with RxJS or Redux
OOP FP
2
???
?? ???
Elm?? ??? ?? redux, cycle.js
?? ?? ?? ???? ???? ??? ?? ??
Rx? ?? ???
??
??? ???? ??
Observable + LINQ + Scheduler
RP and Functional, But Not FRP
??? ?? -> ?? -> ??
??? ???(Compositionality)
??? ????? ?? ??
?????

More Related Content

??? ???????????? ????????? ????? ?????? Rx ??????