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.
h3#definition The Observable: a function at its core
24
28
@@ -61,10 +65,59 @@ h3#observables-vs-promises Observables and Promises: More different than alike
61
65
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
66
the right tool for the job in some situations.
63
67
68
+
h3#operators Operators: Import them and use them
69
+
70
+
:marked
71
+
Operators are pure functions that extend the Observable interface, allow you to perform an action against the Observable
72
+
and return a new Observable. An Observable comes with very few built-in operators and the rest of the operators are
73
+
added to the Observable on demand. There are multiple approaches to make these operators available for use.
74
+
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
106
+
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,
107
+
but this approach doesn't give you the option to chain operators together. If you were building a third-party
108
+
library, this would be the recommended approach as you don't want your library to produce any side-effects
109
+
to the Observable for consumers of your library but for an application, its less desirable.
110
+
111
+
The recommended approach is to import the operators in the file where you use them. Yes, this may lead to
112
+
duplicate imports of operators in multiple files, but more importantly this ensures that the operators
113
+
that are needed are provided by that file. This becomes especially important with lazy loading, where
114
+
certain feature areas may only make use of certain operators. Importing the operators this way ensures
115
+
the operators are available regardless of where and when you use them.
116
+
64
117
h3#managing-subscriptions Managing Subscriptions
65
118
66
119
:marked
67
-
Observables like any other instance use resources and those resources add to the overall resources used in your application. Observables
120
+
Observables like any other instance use resources and those resources add to the overall weight of your application over time. Observables
68
121
provide a `Subscription` for each `Subscriber` of the Observable that comes with a way to _unsubscribe_ or clean up any resources used
69
122
while listening for values produced by the Observable. We'll look at a simple example of how to unsubscribe from and Observable once
The Observables provided by these area can be used together. The same set of functionality and extensibility can be combined together in a very powerful and
253
-
practical way. In order to demonstrate how these work together, you’re going to build a hero search component. Let’s start by gathering some requirements about
254
-
what your typeahead will need.
305
+
The Observables provided by these areas can be used together. The same set of functionality and extensibility can be combined together
306
+
in a very powerful and practical way. A prime example is a hero search component that implements a typeahead search feature.
307
+
Let’s start by gathering some requirements about what your typeahead will need.
0 commit comments