You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 4, 2017. It is now read-only.
Copy file name to clipboardExpand all lines: public/docs/ts/latest/guide/rxjs.jade
+51-1
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,7 @@ block includes
16
16
## Table of Contents
17
17
* [The Observable](#definition "")
18
18
* [Observables and Promises](#observables-vs-promises "")
19
+
* [Operators](#operators "")
19
20
* [Framework APIs](#apis "")
20
21
* [Error Handling](#error-handling "")
21
22
* [Further Reading](#reading "")
@@ -61,10 +62,59 @@ h3#observables-vs-promises Observables and Promises: More different than alike
61
62
tool to handle the various streams of events in an application. So does this mean Promises are no longer needed? Absolutely not. Promises will continue to serve a purpose as
62
63
the right tool for the job in some situations.
63
64
65
+
h3#operators Operators: Import them and use them
66
+
67
+
:marked
68
+
Operators are pure functions that extend the Observable interface, allow you to perform an action against the Observable
69
+
and return a new Observable. An Observable comes with very few built-in operators and the rest of the operators are
70
+
added to the Observable on demand. There are multiple approaches to make these operators available for use.
71
+
One approach is to import the entire RxJS library.
This approach has no side-effects as you're not patching the Observable prototype. It also is
103
+
more conducive to tree shaking versus patching the Observable prototype, which can't be tree-shaken. You're also only importing what you need where you need it,
104
+
but this approach doesn't give you the option to chain operators together. If you were building a third-party
105
+
library, this would be the recommended approach as you don't want your library to produce any side-effects
106
+
to the Observable for consumers of your library but for an application, its less desirable.
107
+
108
+
The recommended approach is to import the operators in the file where you use them. Yes, this may lead to
109
+
duplicate imports of operators in multiple files, but more importantly this ensures that the operators
110
+
that are needed are provided by that file. This becomes especially important with lazy loading, where
111
+
certain feature areas may only make use of certain operators. Importing the operators this way ensures
112
+
the operators are available regardless of where and when you use them.
113
+
64
114
h3#managing-subscriptions Managing Subscriptions
65
115
66
116
:marked
67
-
Observables like any other instance use resources and those resources add to the overall resources used in your application. Observables
117
+
Observables like any other instance use resources and those resources add to the overall weight of your application over time. Observables
68
118
provide a `Subscription` for each `Subscriber` of the Observable that comes with a way to _unsubscribe_ or clean up any resources used
69
119
while listening for values produced by the Observable. We'll look at a simple example of how to unsubscribe from and Observable once
0 commit comments