2
votes

I've been using lodash to transform (map, filter etc.) data in angular 1. Now in @angular (angular 2) one of the first examples showing how to request json with http service uses RxJS's map. I've checked that RxJS has lots more useful operators. So should I convert every collection to Observable ( asObservable() ) and use the operators of RxJS as they are already included and required in @angular?

1

1 Answers

2
votes

If you are working with angular 2, a lot of things coming from the framework will be in the form of an observable. If, in your angular 2 application, you get back an observable, use the observable operators.

This will be the case for forms, http requests, routing, ...

Let's say however you have a dumb application in your application that accepts an array of elements. If you need to do some operation on that array, just handle it as an array and use the operators on the array. There is no benefit in creating an observable from this array.

Bottom line, for everything where you have an observable, which will mostly be returned by the angular 2 framework, treat is an observable with it's operators. If you have an array for some reason, handle it as an array with it's operators.

You'll see that arrays in angular 2 are something that will not be handled to often, since you'll get observables most of the time