![]() ![]() Neither does: const mappedObservable = doBitmap(). Thus, to reemphasize: const bitmapObservable = doBitmap() ĭoes nothing but return an Observable, but doesn’t start production of a bitmap. This was a source of confusion for me, map and its kin can be thought of a formula or a description of what will happen later, when we actually subscribe to the underlying source. This is a style of programming akin to using venerable jQuery's finders or Ruby-on-Rail’s ActiveRecord’s filters.Īnd note that most of the operators do not cause a subscription. So the original observable remains unchanged. So if we replace map with flatMap and run again:Īs an aside, what do map, flatMap and switchMap return? The simple answer is that almost all the operators take in an Observable and return a new Observable. Internally, every time our function returns an Observable the flatMap subscribes each one and sends the data that they produce down the line. Much like array.map (which maps an array to another array) is analogous to array.flatMap (which maps an array of arrays to a “flat” array), observable.flatMap takes an “Observable which produces Observables” and maps it down to the data elements produced just like a “flat” Observable. class Bitmap ) īut Reactive libraries provide a much easier way: Enter 'flatMap’
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |