狠狠撸

狠狠撸Share a Scribd company logo
Reactive Programming 是什麼?
能吃嗎?
By Kevin Yang
Reactive
Programming
?An API for asynchronous
programming
with observable streams
Observer pattern ( 觀察者模式)
? The observer pattern is a software design pattern in which an object,
called the subject, maintains a list of its dependents, called observers,
and notifies them automatically of any state changes, usually by
calling one of their methods.
? 在物件之間定義一個主題和多個觀察者,當主題的狀態改變,觀
察者都會收到通知,並自行更新。
Reactive Programmin
Marble
Diagram (彈
珠圖)
Better Codebases
? Functional
? Avoid intricate stateful programs, using clean input/output functions over
observable streams.
? Less is more
? ReactiveX's operators often reduce what was once an elaborate challenge into a few
lines of code.
? Async error handling
? Traditional try/catch is powerless for errors in asynchronous computations, but
ReactiveX is equipped with proper mechanisms for handling errors.
? Concurrency made easy
? Observables and Schedulers in ReactiveX allow the programmer to abstract away
low-level threading, synchronization, and concurrency issues.
Support Languages
? Java: RxJava
? JavaScript: RxJS
? C#: Rx.NET
? C#(Unity): UniRx
? Scala: RxScala
? Clojure: RxClojure
? C++: RxCpp
? Lua: RxLua
? Ruby: Rx.rb
? Python: RxPY
? Go: RxGo
? Groovy: RxGroovy
? JRuby: RxJRuby
? Kotlin: RxKotlin
? Swift: RxSwift
? PHP: RxPHP
? Elixir: reaxive
? Dart: RxDart
RxJS
RxJS 基本元素
? Observable
? Observer
? Subscription
? Subject
? Operators
? Schedulers
什麼是 Observable
? Any number of values
? Over any amount of time
? Lazy: Set up observation and resources when subscribed to
? Cancellable: Will tear down observation and resources
? Laziness bonus: Can be retried/replayed by calling them again.
? Can be thought of as functions
什麼是 Observer
? Observer is a collection of callbacks that knows how to listen to values
delivered by the Observable.
? Collection of Callbacks如下
? next:Observer接收到一個值
? error : Observer接收到一個錯誤
? complete : Observer接收到完成的訊息
什麼是 Subscription
? Subscription represents the execution of an Observable, is primarily
useful for cancelling the execution.
什麼是 Operator
? Operators are pure functions that enable a functional programming
style of dealing with collections with operators like map, filter, concat,
mergeMap, etc.
Operators 的種類
? Filtering Operators: take, filter, first, ..
? Combination Operators: concat, merge, ..
? Transformation Operators: buffer, debounceTime, ...
? Utility Operation: do
? Error handling Operations: catch, retry …
幾個 Operators 範例
幾個 Operators 範例
幾個 Operators 範例
什麼是 Subject
? A Subject is a special type of Observable that allows values to be
multicasted to many Observables. Subjects are like EventEmitters.
什麼是 Scheduler
? An execution context and a data structure to order tasks and schedule
their execution. Provides a notion of (potentially virtual) time,
through the now() getter method
RxJS Learning Resource
? https://reactive.how/
? https://www.learnrxjs.io/
? http://reactivex.io/rxjs
Demo
範例1: Array 操作
var source = [1,2,3,4,5];
source.map((item) => {
console.log("onNext: "+item);
})
var source = [1,2,3,4,5];
from(source) .pipe(
map((item) => console.log("onNext: "+item))
)
範例2: Event (原生寫法)
<div id="test"></div>
<script>
document.getElementById("test")
.addEventListener("click", function( event ) {
event.target.innerHTML = "click count: " +
event.detail;
}, false);
</script>
範例2: Event (RxJS)
const ele = document.getElementById('test');
fromEvent(ele, 'click').pipe(
map((event: any)=> {
event.target.innerHTML = "click count: " +
event.detail;
return event;
})
).subscribe();
範例3: Painting
範例程式: https://stackblitz.com/edit/rxjs-drag-paint?file=index.ts
import { paint } from './canvas.js';
import { of, fromEvent } from 'rxjs';
import { mergeMap, takeUntil } from 'rxjs/operators';
const move$ = fromEvent(document, 'mousemove');
const down$ = fromEvent(document, 'mousedown');
const up$ = fromEvent(document, 'mouseup');
const paints$ = down$.pipe(
mergeMap(down => move$.pipe(takeUntil(up$)))
);
paints$.subscribe(v=> paint(v));
楊捷凱 (Kevin)
? 微軟 MVP
? Angular / Web Technologies GDE
? Blog:https://blog.kevinyang.net/
? FB Page:https://www.facebook.com/CKNotepad
? Organizers:
? Angular Taiwan
? Angular Girls Taiwan
? Angular 線上讀書會

More Related Content

Similar to Reactive Programmin (20)

Predictable reactive state management - ngrx
Predictable reactive state management - ngrxPredictable reactive state management - ngrx
Predictable reactive state management - ngrx
Ilia Idakiev
?
Kubernetes Infra 2.0
Kubernetes Infra 2.0Kubernetes Infra 2.0
Kubernetes Infra 2.0
Deepak Sood
?
Reactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaReactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-Java
Kasun Indrasiri
?
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
Peter Lawrey
?
Kubernetes 101
Kubernetes 101Kubernetes 101
Kubernetes 101
Huy Vo
?
Solve it Differently with Reactive Programming
Solve it Differently with Reactive ProgrammingSolve it Differently with Reactive Programming
Solve it Differently with Reactive Programming
Supun Dissanayake
?
Java8
Java8Java8
Java8
Jaime L. López Carratalá
?
Reactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaReactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJava
NexThoughts Technologies
?
Reactive Programming in Java and Spring Framework 5
Reactive Programming in Java and Spring Framework 5Reactive Programming in Java and Spring Framework 5
Reactive Programming in Java and Spring Framework 5
Richard Langlois P. Eng.
?
Reactive Thinking in Java
Reactive Thinking in JavaReactive Thinking in Java
Reactive Thinking in Java
Yakov Fain
?
Distributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and ScalaDistributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and Scala
Max Alexejev
?
Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?
GetInData
?
Observability beyond logging for Java Microservices
Observability beyond logging for Java MicroservicesObservability beyond logging for Java Microservices
Observability beyond logging for Java Microservices
Luke Marsden
?
Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design pattern
Nitin Bhide
?
Observables in Angular
Observables in AngularObservables in Angular
Observables in Angular
Knoldus Inc.
?
Architecting for Microservices Part 2
Architecting for Microservices Part 2Architecting for Microservices Part 2
Architecting for Microservices Part 2
Elana Krasner
?
20160609 nike techtalks reactive applications tools of the trade
20160609 nike techtalks reactive applications   tools of the trade20160609 nike techtalks reactive applications   tools of the trade
20160609 nike techtalks reactive applications tools of the trade
shinolajla
?
Microservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive ProgrammingMicroservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive Programming
Araf Karsh Hamid
?
Reactive solutions using java 9 and spring reactor
Reactive solutions using java 9 and spring reactorReactive solutions using java 9 and spring reactor
Reactive solutions using java 9 and spring reactor
OrenEzer1
?
Building Reactive applications with Akka
Building Reactive applications with AkkaBuilding Reactive applications with Akka
Building Reactive applications with Akka
Knoldus Inc.
?
Predictable reactive state management - ngrx
Predictable reactive state management - ngrxPredictable reactive state management - ngrx
Predictable reactive state management - ngrx
Ilia Idakiev
?
Kubernetes Infra 2.0
Kubernetes Infra 2.0Kubernetes Infra 2.0
Kubernetes Infra 2.0
Deepak Sood
?
Reactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaReactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-Java
Kasun Indrasiri
?
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
Peter Lawrey
?
Kubernetes 101
Kubernetes 101Kubernetes 101
Kubernetes 101
Huy Vo
?
Solve it Differently with Reactive Programming
Solve it Differently with Reactive ProgrammingSolve it Differently with Reactive Programming
Solve it Differently with Reactive Programming
Supun Dissanayake
?
Reactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaReactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJava
NexThoughts Technologies
?
Reactive Programming in Java and Spring Framework 5
Reactive Programming in Java and Spring Framework 5Reactive Programming in Java and Spring Framework 5
Reactive Programming in Java and Spring Framework 5
Richard Langlois P. Eng.
?
Reactive Thinking in Java
Reactive Thinking in JavaReactive Thinking in Java
Reactive Thinking in Java
Yakov Fain
?
Distributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and ScalaDistributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and Scala
Max Alexejev
?
Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?
GetInData
?
Observability beyond logging for Java Microservices
Observability beyond logging for Java MicroservicesObservability beyond logging for Java Microservices
Observability beyond logging for Java Microservices
Luke Marsden
?
Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design pattern
Nitin Bhide
?
Observables in Angular
Observables in AngularObservables in Angular
Observables in Angular
Knoldus Inc.
?
Architecting for Microservices Part 2
Architecting for Microservices Part 2Architecting for Microservices Part 2
Architecting for Microservices Part 2
Elana Krasner
?
20160609 nike techtalks reactive applications tools of the trade
20160609 nike techtalks reactive applications   tools of the trade20160609 nike techtalks reactive applications   tools of the trade
20160609 nike techtalks reactive applications tools of the trade
shinolajla
?
Microservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive ProgrammingMicroservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive Programming
Araf Karsh Hamid
?
Reactive solutions using java 9 and spring reactor
Reactive solutions using java 9 and spring reactorReactive solutions using java 9 and spring reactor
Reactive solutions using java 9 and spring reactor
OrenEzer1
?
Building Reactive applications with Akka
Building Reactive applications with AkkaBuilding Reactive applications with Akka
Building Reactive applications with Akka
Knoldus Inc.
?

More from Chieh Kai Yang (11)

Dotnet Conf 2021 - F# and Safe Stack
Dotnet Conf 2021 - F# and Safe StackDotnet Conf 2021 - F# and Safe Stack
Dotnet Conf 2021 - F# and Safe Stack
Chieh Kai Yang
?
无密码时代终於要来了吗
无密码时代终於要来了吗无密码时代终於要来了吗
无密码时代终於要来了吗
Chieh Kai Yang
?
Structured data
Structured dataStructured data
Structured data
Chieh Kai Yang
?
Web.dev extended : What's new in Web [GDG Taichung]
Web.dev extended : What's new in Web [GDG Taichung]Web.dev extended : What's new in Web [GDG Taichung]
Web.dev extended : What's new in Web [GDG Taichung]
Chieh Kai Yang
?
Study4TW - .NET Conf 2019 - Rx
Study4TW - .NET Conf 2019 - RxStudy4TW - .NET Conf 2019 - Rx
Study4TW - .NET Conf 2019 - Rx
Chieh Kai Yang
?
從零走到 Angular 世界
從零走到 Angular 世界從零走到 Angular 世界
從零走到 Angular 世界
Chieh Kai Yang
?
改善 Angular 開發流程:你所不知道的 Schematics 程式碼產生器
改善 Angular 開發流程:你所不知道的 Schematics 程式碼產生器改善 Angular 開發流程:你所不知道的 Schematics 程式碼產生器
改善 Angular 開發流程:你所不知道的 Schematics 程式碼產生器
Chieh Kai Yang
?
Study4.TW .NET Conf 2018 - Fp in c#
Study4.TW .NET Conf 2018  - Fp in c#Study4.TW .NET Conf 2018  - Fp in c#
Study4.TW .NET Conf 2018 - Fp in c#
Chieh Kai Yang
?
How to 系列 - Hosting a website
How to 系列 - Hosting a websiteHow to 系列 - Hosting a website
How to 系列 - Hosting a website
Chieh Kai Yang
?
2018-01-06 Study4Love Conference - Rendertron
2018-01-06 Study4Love Conference - Rendertron2018-01-06 Study4Love Conference - Rendertron
2018-01-06 Study4Love Conference - Rendertron
Chieh Kai Yang
?
ModernWeb 2017 angular component
ModernWeb 2017 angular componentModernWeb 2017 angular component
ModernWeb 2017 angular component
Chieh Kai Yang
?
Dotnet Conf 2021 - F# and Safe Stack
Dotnet Conf 2021 - F# and Safe StackDotnet Conf 2021 - F# and Safe Stack
Dotnet Conf 2021 - F# and Safe Stack
Chieh Kai Yang
?
无密码时代终於要来了吗
无密码时代终於要来了吗无密码时代终於要来了吗
无密码时代终於要来了吗
Chieh Kai Yang
?
Web.dev extended : What's new in Web [GDG Taichung]
Web.dev extended : What's new in Web [GDG Taichung]Web.dev extended : What's new in Web [GDG Taichung]
Web.dev extended : What's new in Web [GDG Taichung]
Chieh Kai Yang
?
Study4TW - .NET Conf 2019 - Rx
Study4TW - .NET Conf 2019 - RxStudy4TW - .NET Conf 2019 - Rx
Study4TW - .NET Conf 2019 - Rx
Chieh Kai Yang
?
從零走到 Angular 世界
從零走到 Angular 世界從零走到 Angular 世界
從零走到 Angular 世界
Chieh Kai Yang
?
改善 Angular 開發流程:你所不知道的 Schematics 程式碼產生器
改善 Angular 開發流程:你所不知道的 Schematics 程式碼產生器改善 Angular 開發流程:你所不知道的 Schematics 程式碼產生器
改善 Angular 開發流程:你所不知道的 Schematics 程式碼產生器
Chieh Kai Yang
?
Study4.TW .NET Conf 2018 - Fp in c#
Study4.TW .NET Conf 2018  - Fp in c#Study4.TW .NET Conf 2018  - Fp in c#
Study4.TW .NET Conf 2018 - Fp in c#
Chieh Kai Yang
?
How to 系列 - Hosting a website
How to 系列 - Hosting a websiteHow to 系列 - Hosting a website
How to 系列 - Hosting a website
Chieh Kai Yang
?
2018-01-06 Study4Love Conference - Rendertron
2018-01-06 Study4Love Conference - Rendertron2018-01-06 Study4Love Conference - Rendertron
2018-01-06 Study4Love Conference - Rendertron
Chieh Kai Yang
?
ModernWeb 2017 angular component
ModernWeb 2017 angular componentModernWeb 2017 angular component
ModernWeb 2017 angular component
Chieh Kai Yang
?

Recently uploaded (20)

EaseUS Partition Master Crack 2025 + Serial Key
EaseUS Partition Master Crack 2025 + Serial KeyEaseUS Partition Master Crack 2025 + Serial Key
EaseUS Partition Master Crack 2025 + Serial Key
kherorpacca127
?
Technology use over time and its impact on consumers and businesses.pptx
Technology use over time and its impact on consumers and businesses.pptxTechnology use over time and its impact on consumers and businesses.pptx
Technology use over time and its impact on consumers and businesses.pptx
kaylagaze
?
What Makes "Deep Research"? A Dive into AI Agents
What Makes "Deep Research"? A Dive into AI AgentsWhat Makes "Deep Research"? A Dive into AI Agents
What Makes "Deep Research"? A Dive into AI Agents
Zilliz
?
SMART SENTRY CYBER THREAT INTELLIGENCE IN IIOT
SMART SENTRY CYBER THREAT INTELLIGENCE IN IIOTSMART SENTRY CYBER THREAT INTELLIGENCE IN IIOT
SMART SENTRY CYBER THREAT INTELLIGENCE IN IIOT
TanmaiArni
?
1.1. Evolution-and-Scope-of-Business-Analytics.pptx
1.1. Evolution-and-Scope-of-Business-Analytics.pptx1.1. Evolution-and-Scope-of-Business-Analytics.pptx
1.1. Evolution-and-Scope-of-Business-Analytics.pptx
Jitendra Tomar
?
The Future of Repair: Transparent and Incremental by Botond De?nes
The Future of Repair: Transparent and Incremental by Botond De?nesThe Future of Repair: Transparent and Incremental by Botond De?nes
The Future of Repair: Transparent and Incremental by Botond De?nes
ScyllaDB
?
Wondershare Dr.Fone Crack Free Download 2025
Wondershare Dr.Fone Crack Free Download 2025Wondershare Dr.Fone Crack Free Download 2025
Wondershare Dr.Fone Crack Free Download 2025
maharajput103
?
Unlocking DevOps Secuirty :Vault & Keylock
Unlocking DevOps Secuirty :Vault & KeylockUnlocking DevOps Secuirty :Vault & Keylock
Unlocking DevOps Secuirty :Vault & Keylock
HusseinMalikMammadli
?
Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]
Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]
Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]
Jonathan Bowen
?
DevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdfDevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdf
Justin Reock
?
[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps
[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps
[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps
Safe Software
?
TrustArc Webinar - Building your DPIA/PIA Program: Best Practices & Tips
TrustArc Webinar - Building your DPIA/PIA Program: Best Practices & TipsTrustArc Webinar - Building your DPIA/PIA Program: Best Practices & Tips
TrustArc Webinar - Building your DPIA/PIA Program: Best Practices & Tips
TrustArc
?
World Information Architecture Day 2025 - UX at a Crossroads
World Information Architecture Day 2025 - UX at a CrossroadsWorld Information Architecture Day 2025 - UX at a Crossroads
World Information Architecture Day 2025 - UX at a Crossroads
Joshua Randall
?
Technology use over time and its impact on consumers and businesses.pptx
Technology use over time and its impact on consumers and businesses.pptxTechnology use over time and its impact on consumers and businesses.pptx
Technology use over time and its impact on consumers and businesses.pptx
kaylagaze
?
How Discord Indexes Trillions of Messages: Scaling Search Infrastructure by V...
How Discord Indexes Trillions of Messages: Scaling Search Infrastructure by V...How Discord Indexes Trillions of Messages: Scaling Search Infrastructure by V...
How Discord Indexes Trillions of Messages: Scaling Search Infrastructure by V...
ScyllaDB
?
UiPath Agentic Automation Capabilities and Opportunities
UiPath Agentic Automation Capabilities and OpportunitiesUiPath Agentic Automation Capabilities and Opportunities
UiPath Agentic Automation Capabilities and Opportunities
DianaGray10
?
Future-Proof Your Career with AI Options
Future-Proof Your  Career with AI OptionsFuture-Proof Your  Career with AI Options
Future-Proof Your Career with AI Options
DianaGray10
?
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog GavraReplacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
ScyllaDB
?
Field Device Management Market Report 2030 - TechSci Research
Field Device Management Market Report 2030 - TechSci ResearchField Device Management Market Report 2030 - TechSci Research
Field Device Management Market Report 2030 - TechSci Research
Vipin Mishra
?
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
ScyllaDB
?
EaseUS Partition Master Crack 2025 + Serial Key
EaseUS Partition Master Crack 2025 + Serial KeyEaseUS Partition Master Crack 2025 + Serial Key
EaseUS Partition Master Crack 2025 + Serial Key
kherorpacca127
?
Technology use over time and its impact on consumers and businesses.pptx
Technology use over time and its impact on consumers and businesses.pptxTechnology use over time and its impact on consumers and businesses.pptx
Technology use over time and its impact on consumers and businesses.pptx
kaylagaze
?
What Makes "Deep Research"? A Dive into AI Agents
What Makes "Deep Research"? A Dive into AI AgentsWhat Makes "Deep Research"? A Dive into AI Agents
What Makes "Deep Research"? A Dive into AI Agents
Zilliz
?
SMART SENTRY CYBER THREAT INTELLIGENCE IN IIOT
SMART SENTRY CYBER THREAT INTELLIGENCE IN IIOTSMART SENTRY CYBER THREAT INTELLIGENCE IN IIOT
SMART SENTRY CYBER THREAT INTELLIGENCE IN IIOT
TanmaiArni
?
1.1. Evolution-and-Scope-of-Business-Analytics.pptx
1.1. Evolution-and-Scope-of-Business-Analytics.pptx1.1. Evolution-and-Scope-of-Business-Analytics.pptx
1.1. Evolution-and-Scope-of-Business-Analytics.pptx
Jitendra Tomar
?
The Future of Repair: Transparent and Incremental by Botond De?nes
The Future of Repair: Transparent and Incremental by Botond De?nesThe Future of Repair: Transparent and Incremental by Botond De?nes
The Future of Repair: Transparent and Incremental by Botond De?nes
ScyllaDB
?
Wondershare Dr.Fone Crack Free Download 2025
Wondershare Dr.Fone Crack Free Download 2025Wondershare Dr.Fone Crack Free Download 2025
Wondershare Dr.Fone Crack Free Download 2025
maharajput103
?
Unlocking DevOps Secuirty :Vault & Keylock
Unlocking DevOps Secuirty :Vault & KeylockUnlocking DevOps Secuirty :Vault & Keylock
Unlocking DevOps Secuirty :Vault & Keylock
HusseinMalikMammadli
?
Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]
Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]
Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]
Jonathan Bowen
?
DevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdfDevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdf
Justin Reock
?
[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps
[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps
[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps
Safe Software
?
TrustArc Webinar - Building your DPIA/PIA Program: Best Practices & Tips
TrustArc Webinar - Building your DPIA/PIA Program: Best Practices & TipsTrustArc Webinar - Building your DPIA/PIA Program: Best Practices & Tips
TrustArc Webinar - Building your DPIA/PIA Program: Best Practices & Tips
TrustArc
?
World Information Architecture Day 2025 - UX at a Crossroads
World Information Architecture Day 2025 - UX at a CrossroadsWorld Information Architecture Day 2025 - UX at a Crossroads
World Information Architecture Day 2025 - UX at a Crossroads
Joshua Randall
?
Technology use over time and its impact on consumers and businesses.pptx
Technology use over time and its impact on consumers and businesses.pptxTechnology use over time and its impact on consumers and businesses.pptx
Technology use over time and its impact on consumers and businesses.pptx
kaylagaze
?
How Discord Indexes Trillions of Messages: Scaling Search Infrastructure by V...
How Discord Indexes Trillions of Messages: Scaling Search Infrastructure by V...How Discord Indexes Trillions of Messages: Scaling Search Infrastructure by V...
How Discord Indexes Trillions of Messages: Scaling Search Infrastructure by V...
ScyllaDB
?
UiPath Agentic Automation Capabilities and Opportunities
UiPath Agentic Automation Capabilities and OpportunitiesUiPath Agentic Automation Capabilities and Opportunities
UiPath Agentic Automation Capabilities and Opportunities
DianaGray10
?
Future-Proof Your Career with AI Options
Future-Proof Your  Career with AI OptionsFuture-Proof Your  Career with AI Options
Future-Proof Your Career with AI Options
DianaGray10
?
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog GavraReplacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
ScyllaDB
?
Field Device Management Market Report 2030 - TechSci Research
Field Device Management Market Report 2030 - TechSci ResearchField Device Management Market Report 2030 - TechSci Research
Field Device Management Market Report 2030 - TechSci Research
Vipin Mishra
?
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
ScyllaDB
?

Reactive Programmin

  • 2. Reactive Programming ?An API for asynchronous programming with observable streams
  • 3. Observer pattern ( 觀察者模式) ? The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. ? 在物件之間定義一個主題和多個觀察者,當主題的狀態改變,觀 察者都會收到通知,並自行更新。
  • 6. Better Codebases ? Functional ? Avoid intricate stateful programs, using clean input/output functions over observable streams. ? Less is more ? ReactiveX's operators often reduce what was once an elaborate challenge into a few lines of code. ? Async error handling ? Traditional try/catch is powerless for errors in asynchronous computations, but ReactiveX is equipped with proper mechanisms for handling errors. ? Concurrency made easy ? Observables and Schedulers in ReactiveX allow the programmer to abstract away low-level threading, synchronization, and concurrency issues.
  • 7. Support Languages ? Java: RxJava ? JavaScript: RxJS ? C#: Rx.NET ? C#(Unity): UniRx ? Scala: RxScala ? Clojure: RxClojure ? C++: RxCpp ? Lua: RxLua ? Ruby: Rx.rb ? Python: RxPY ? Go: RxGo ? Groovy: RxGroovy ? JRuby: RxJRuby ? Kotlin: RxKotlin ? Swift: RxSwift ? PHP: RxPHP ? Elixir: reaxive ? Dart: RxDart
  • 9. RxJS 基本元素 ? Observable ? Observer ? Subscription ? Subject ? Operators ? Schedulers
  • 10. 什麼是 Observable ? Any number of values ? Over any amount of time ? Lazy: Set up observation and resources when subscribed to ? Cancellable: Will tear down observation and resources ? Laziness bonus: Can be retried/replayed by calling them again. ? Can be thought of as functions
  • 11. 什麼是 Observer ? Observer is a collection of callbacks that knows how to listen to values delivered by the Observable. ? Collection of Callbacks如下 ? next:Observer接收到一個值 ? error : Observer接收到一個錯誤 ? complete : Observer接收到完成的訊息
  • 12. 什麼是 Subscription ? Subscription represents the execution of an Observable, is primarily useful for cancelling the execution.
  • 13. 什麼是 Operator ? Operators are pure functions that enable a functional programming style of dealing with collections with operators like map, filter, concat, mergeMap, etc.
  • 14. Operators 的種類 ? Filtering Operators: take, filter, first, .. ? Combination Operators: concat, merge, .. ? Transformation Operators: buffer, debounceTime, ... ? Utility Operation: do ? Error handling Operations: catch, retry …
  • 18. 什麼是 Subject ? A Subject is a special type of Observable that allows values to be multicasted to many Observables. Subjects are like EventEmitters.
  • 19. 什麼是 Scheduler ? An execution context and a data structure to order tasks and schedule their execution. Provides a notion of (potentially virtual) time, through the now() getter method
  • 20. RxJS Learning Resource ? https://reactive.how/ ? https://www.learnrxjs.io/ ? http://reactivex.io/rxjs
  • 21. Demo
  • 22. 範例1: Array 操作 var source = [1,2,3,4,5]; source.map((item) => { console.log("onNext: "+item); }) var source = [1,2,3,4,5]; from(source) .pipe( map((item) => console.log("onNext: "+item)) )
  • 23. 範例2: Event (原生寫法) <div id="test"></div> <script> document.getElementById("test") .addEventListener("click", function( event ) { event.target.innerHTML = "click count: " + event.detail; }, false); </script>
  • 24. 範例2: Event (RxJS) const ele = document.getElementById('test'); fromEvent(ele, 'click').pipe( map((event: any)=> { event.target.innerHTML = "click count: " + event.detail; return event; }) ).subscribe();
  • 25. 範例3: Painting 範例程式: https://stackblitz.com/edit/rxjs-drag-paint?file=index.ts import { paint } from './canvas.js'; import { of, fromEvent } from 'rxjs'; import { mergeMap, takeUntil } from 'rxjs/operators'; const move$ = fromEvent(document, 'mousemove'); const down$ = fromEvent(document, 'mousedown'); const up$ = fromEvent(document, 'mouseup'); const paints$ = down$.pipe( mergeMap(down => move$.pipe(takeUntil(up$))) ); paints$.subscribe(v=> paint(v));
  • 26. 楊捷凱 (Kevin) ? 微軟 MVP ? Angular / Web Technologies GDE ? Blog:https://blog.kevinyang.net/ ? FB Page:https://www.facebook.com/CKNotepad ? Organizers: ? Angular Taiwan ? Angular Girls Taiwan ? Angular 線上讀書會