- PHP Reactive Programming
- Martin Sikora
- 351字
- 2021-07-09 19:06:16
Naming conventions in Reactive Extensions
When talking about Observables, we use terms such as emit/send value/item. Commonly, we say that an Observable emits an item, but we understand the same from an Observable sends a value as well.
By emit/send we mean that an Observable is calling the onNext
method on an observer.
When talking about Observables, we use terms such as send error/complete notification/signal. We also often mention that an Observable completes, which means that an Observable has sent a complete notification.
By notification/signal we mean that an Observable is calling the onError
or onComplete
method on an observer.
In the preceding paragraph, we worked with a simple RxPHP demo that had one Observable, two operators and one observer.
This structure formed an operator/Observable chain. We'll understand the same thing from both of the terms operator chain and Observable chain (sometimes also referred to as a chain of Observable operators). This is because, from our perspective, we're chaining operators; but under the hood, each operator returns another instance of the Observable
class, so, in fact, we're chaining Observables. In practice, this doesn't matter, so we'll just remember that these have the same meaning.
When talking about Observable chains, we sometimes use the term source Observable. This is the source of items in the chain. In other words, it's the first Observable in the chain. In the preceding example, the source Observable was Observable::fromArray($fruits)
.
When talking about operators, we use the term source Observable to also describe the Observable directly preceding this particular operator (because it's the source of items for this operator).
Sometimes instead of the onNext
, onError
and onComplete
terms and method names, you'll encounter just next
, error
and complete
. This comes from RxJS 5, which follows the ES7 Observable specification ( https://github.com/tc39/proposal-observable ), but their meaning is exactly the same. Most Rx implementations use the names onNext
, onError
and onComplete
.
All these terms are used in various literature and articles regarding Rx, so we'll tolerate all of them.