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.
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.
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