89

Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

  • Upload
    others

  • View
    91

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?
Page 2: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

REACTIVE PROGRAMMING & STREAM WITH CYCLE.JS

Jasin Yip

Page 3: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

Reactive Programming & Stream with Cycle.js

SELF INTRODUCTION

▸ 叶俊星(Jasin Yip)

▸ 美团点评 资深前端⼯工程师

▸ 知乎前端开发、 JavaScript 话题优秀回答者

▸ CyclejsCN(Cycle.js 中⽂文社区)发起者

Page 4: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

Reactive Programming & Stream with Cycle.js

OVERVIEW

▸ Introduction

▸ What is reactive programming?

▸ What is stream?

▸ Cycle.js - What if the user was a function? \~/

Page 5: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

WHAT IS REACTIVE PROGRAMMING?

Page 6: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is reactive programming?

Page 7: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is reactive programming?

▸ Imperative Programming

▸ When b or c changed, no effect on a.

▸ Reactive Programming

▸ When b or c changed, a automatically updated.

Page 8: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Reactive Programming?

WHY SHOULD WE USE REACTIVE PROGRAMMING?

Page 9: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

Why Should we use reactive programming?

HTTP REQUEST COUNTER

For example: count HTTP request times

Page 10: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

Why Should we use reactive programming?

HTTP REQUEST COUNTER

PROACTIVE PASSIVE

class HttpRequest { // … send () { // … counter.increment() }}

Page 11: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

Why Should we use reactive programming?

HTTP REQUEST COUNTER

Page 12: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

Why Should we use reactive programming?

HTTP REQUEST COUNTER

Page 13: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

Why Should we use reactive programming?

HTTP REQUEST COUNTER

class HttpRequest { // … send () { // … eventBus.emit('requestDone') }}

class Counter { constructor (eventBus) {

eventBus.on('requestDone') .then(this.increment)

}, // …}

LISTENABLE REACTIVE

Page 14: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

Why Should we use reactive programming?

Passive Reactive

How does Counter work? Find usages Look inside

Proactive Listenable

Which modules are affected by HttpRequest? Look inside Find usages

Page 15: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

Separation of Concerns

The Selling Point of Reactive Programming

Why Should we use reactive programming?

Page 16: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Reactive Programming?

WAYS TO IMPLEMENT REACTIVE PROGRAMMING

▸ EventBus

▸ Object.defineProperties

▸ ES2015 Proxy

▸ Streams (with some libraries like RxJS, xstream)

▸ …

Page 17: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

WHAT IS STREAM?

Page 18: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Stream?

A typical array:

Space

Page 19: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Stream?

A typical stream:

Events

time

Page 20: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Stream?

▸ Array: sequence over space

▸ Stream: sequence over time

1 2 3

1 2 3

Page 21: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Stream?

[1, 2, 3]

[2, 4, 6]

map(e => e * 2)

Page 22: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Stream?

[2, 6, 9]

[2, 6]

filter(e => e < 7)

Page 23: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Stream?

map(e => e * 2)

1 2 3

2 4 6

Page 24: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Stream?

filter(e => e < 7)

2 6 9

2 6

Page 25: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Stream?

time

Page 26: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Stream?

delay(2000)

1 2 3

1 2 3

Page 27: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Stream?

merge

Page 28: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Stream?

USAGE SCENARIOS (abstract froms and tos)

State

Application default

configuration

HTTP requests

LocalStorage

WebSocket Messages

Multiple sources

mutate

the same state

……User events

Page 29: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Stream?

USAGE SCENARIOS (abstract froms and tos)

State

To display

To merge with

To send

Multiple places

use

the same state

……

Page 30: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Stream?

const changeTodo = todo => { dispatch({ type: 'updateTodo', payload: todo })}const changefromDOMEvent = () => { const todo = formState changeTodo(todo)}const changefromWebSocket = () => { const todo = fromWS changeTodo(todo)}

Normally using Redux:

Page 31: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Stream?

USAGE SCENARIOS (abstract froms and tos)

Todos

DOM Event

WebSocket

Page 32: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Stream?

const changeFromDOMEvent$ = Rx.Observable .fromEvent($('.btn', 'click')) .map(evt => evt.data)const changeFromWebSocket$ = Rx.Observable .fromEvent(ws, 'message') .map(evt => evt.data)

// Merge all data sourceconst changes$ = Rx.Observable.merge( changeFromDOMEvent$, changeFromWebSocket$)changes$.subscribe(todo => dispatch({ type: 'updateTodo', payload: todo }))

Using stream(with RxJS):

Page 33: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Stream?

USAGE SCENARIOS (abstract froms and tos)

Todos

Send Ajax to save

Display

Page 34: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

房间数离店⽇日期

价格&优惠

⼊入住⽇日期

原价格

优惠类型

优惠1信息

优惠2价格

优惠3折扣&峰

⽤用户选择优惠⽅方

⽀支付价格

⼊入住信息

优惠1优惠价格

优惠3优惠价格

CombineLatest

FlattenMapMap

Map

Map

Map

Zip

Map

Zip

Zip优惠价格汇

价格&优惠结

CombineLatest

Zip

Reactive programming & stream processing in our production usage.

Page 35: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

Just use stream!

The solution for the complicate situation below

What is Stream?

Page 36: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

WHAT IF THE USER WAS A FUNCTION?

Page 37: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

JAVASCRIPT IN 2016/2017

Immutable data strucutres

Redux

Shadow DOMState and props

Components

One-way data bindingVuex

mobx

declarative

Curosrs

Immutable

Flux

Dispatcher

Page 38: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

NATURAL

Page 39: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

Computer

Human

Page 40: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

Computer

Human

Page 41: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

▸ Insight #1: UIs are cycles

Page 42: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

Computer

Human

Input Devices Output Devices

Page 43: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

Input

Output

function

Page 44: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

▸ Insight #1: UIs are cycles

▸ Insight #2: UIs are functions

Page 45: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?
Page 46: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

▸ Insight #1: UIs are cycles

▸ Insight #2: UIs are functions

▸ Insight #3: UIs are async

Page 47: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

Computer

Human

Page 48: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

Computer

Human

Page 49: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

▸ Insight #1: UIs are cycles

▸ Insight #2: UIs are functions

▸ Insight #3: UIs are async

▸ Insight #4: UIs are symmetric

Page 50: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

Computer

Human

Output Devices Input Devices

Page 51: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

Input

Output

Page 52: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

▸ Insight #1: UIs are cycles

▸ Insight #2: UIs are functions

▸ Insight #3: UIs are async

▸ Insight #4: UIs are symmetric

▸ Insight #5: The user is a function

Page 53: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What is Reactive Programming?

HOW TO CODE IT?

Page 54: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

Computer

cyclejs.cn

interactionStream

screenStream

Page 55: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

function computer (url: EventStream<String>): EventStream<screen> { // …}

let screenStream = computer(interactionStream) screenStream.listen(function (ev) { ... })

Page 56: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

scroll scroll scroll clickinteractionStream

screenStream

scroll scroll scroll click

User

Page 57: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

function user (screenStream: EventStream): EventStream { // Need your brain here...}

Page 58: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

scroll scroll scroll clickinteractionStream

screenStream

scroll scroll scroll click

User

Page 59: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

scroll scroll scroll clickinteractionStream

screenStream

DOM EVENT DISPATCHER

DOM SCREEN EYES BRAIN HANDS

scroll scroll scroll click

DOM EVENT DISPATCHER

DOM SCREEN EYES BRAIN HANDS

Page 60: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

scroll scroll scroll clickinteractionStream

screenStream

DOM EVENT DISPATCHER

DOM SCREEN EYES BRAIN HANDS

scroll scroll scroll click

DOM EVENT DISPATCHER

DOM SCREEN EYES BRAIN HANDS

Page 61: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

scroll scroll scroll clickinteractionStream

screenStream

DOM EVENT DISPATCHER

DOM SCREEN EYES BRAIN HANDS

scroll scroll scroll click

DOM EVENT DISPATCHER

DOM SCREEN EYES BRAIN HANDS These are "Remote"

Page 62: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

function user (screenStream: EventStream): EventStream {

} // Need your brain here...

Page 63: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

function user (screenStream: EventStream): EventStream {

}

screenStream.listen(function (screen) { renderToDOM(screen) }) let interactionEvents = new EventStream() document.addEventListener('*', function (ev) { interactionEvents.emit(ev) }) return interactionEvents

Page 64: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

function user (screenStream: EventStream): EventStream {

}

screenStream.listen(function (screen) { renderToDOM(screen) }) let interactionEvents = new EventStream() document.addEventListener('*', function (ev) { interactionEvents.emit(ev) }) return interactionEvents

Page 65: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

function user (screenStream: EventStream): EventStream {

}

screenStream.listen(function (screen) { renderToDOM(screen) }) let interactionEvents = new EventStream() document.addEventListener('*', function (ev) { interactionEvents.emit(ev) }) return interactionEvents

Page 66: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

let interactionStream = user(screenStream.listen) interactionStream.listen(function (ev) { ... })

Page 67: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

let screenStream = computer(interactionStream)let interactionStream = user(screenStream)

Page 68: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

let screenStream = computer(interactionStream)let interactionStream = user(screenStream)

let a = f(b)let b = g(a)

Page 69: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

let screenStream = computer(interactionStream)let interactionStream = user(screenStream)

let a = f(b)let b = g(a)

let b = g(f(b))

Page 70: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?
Page 71: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

let screenStream = computer(interactionStream)let interactionStream2 = user(screenStream)

let interactionStream = makeEmptyEventStream()

Page 72: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

let screenStream = computer(interactionStream)let interactionStream2 = user(screenStream)

let interactionStream = makeEmptyEventStream()

Page 73: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

scroll scroll scroll clickinteractionStream2

First Screen

scroll scroll scroll click

user

interactionStream

computer

Page 74: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

scroll scroll scroll clickinteractionStream2

screenStream

scroll scroll scroll click

user

interactionStream

computer

Page 75: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

scroll scroll scroll clickinteractionStream2

screenStream

user

interactionStream

computer

Page 76: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

let screenStream = computer(interactionStream)let interactionStream2 = user(screenStream)

let interactionStream = makeEmptyEventStream()

interactionStream2.listen(function (ev) { interactionStream.emit(ev)})

Page 77: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

let screenStream = computer(interactionStream)let interactionStream2 = user(screenStream)

let interactionStream = makeEmptyEventStream()

interactionStream2.listen(function (ev) { interactionStream.emit(ev)})

Page 78: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

let screenStream = computer(interactionStream)let interactionStream2 = user(screenStream)

let interactionStream = makeEmptyEventStream()

interactionStream2.listen(function (ev) { interactionStream.emit(ev)})

Page 79: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

CYCLE.JS

Page 80: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

Computer

Human

Page 81: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

Human

Human

?

Page 82: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

Jasin

Hi Jasin

JasinHow are you?

Alice

Page 83: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

Alice

Alice

How are you?

Jasin

I'm good

Page 84: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

merge

Hi Jasin I'm good

How are you?

Hi Jasin I'm goodHow are you?

Jasin

Alice

Page 85: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

What if the user was a function?

merge

Hi Jasin I'm good

How are you?

Hi Jasin I'm goodHow are you?

Jasin

Alice

CONVERSATION!

Page 86: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

ONE MORE THING...

Page 87: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

Cyclejs.cn

Page 88: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

THANKS!

Page 89: Reactive Programming & Stream Programming - 前端圈 Programming... · Reactive Programming & Stream with Cycle.js OVERVIEW Introduction What is reactive programming? What is stream?

Reactive Programming & Stream

REFERENCE

▸ Cycle.js

▸ RxJS

▸ Functional Programming - 6.1 Streams

▸ What if the user was a function? ——Andre staltz

▸ 流动的数据——使⽤用 RxJS 构造复杂单⻚页应⽤用的数据逻辑 ——徐⻜飞

▸ 单⻚页应⽤用的数据流⽅方案探索 ——徐⻜飞