Skip to main content

Recursivity and Observables: yes it is possible

When writing a loop using a paging API to fetch data for an Angular app, I felt so frustrated  that I was very close to going back to Promises.

I came across lot of questions on the web but no convincing answers: some even proposing to subscribe to an Observable within the service implementation. However, I did not abandon  Observables to return using Promises thanks to this very informative comparison. From there I picked an excellent article on reactive programming with RxJava which gave me hope.

So I kept on trying...

Achieving both reactivity and recursivity without understanding the fundamentals of RxJs operators, was a struggle.

After focussing on the use of the map and mergeMap operators, I managed a first implementation very similar to how I would write a solution to the same problem using Promises. To help me and others who have the same questions, I created a repository of angular code snippets. One is about RxJs Recursive Observable.

Expand operator to the rescue...

Notes about the expand operator

As a second stage, I introduced the reactive behaviour with the expand operator which I came across in the post. The RxJs Observable reactive recursivity code snippet illustrates the use of the expand operator to read a paging API.

Your feedback is very much appreciated, do not hesitate to comment ....

Comments

Popular posts from this blog

Looking for a web framework ...

I recently attended the Rich Web Applications course given by Spring Source, and I was surprised that the technology stack employed in the course was "equivalent" to what I used 8 years ago! It's equivalent in the sense that: Struts 1.2 was then the framework for implementing the Front Controller pattern Tiles with JSPs and JSTL was the view mechanism The course used Spring MVC which is the MODERN equivalent of Struts. Spring MVC is much more powerful but the functionality it provides is about the same as Struts. The element that really surprised me was the fact that Tiles was the proposed mechanism for the view layer. I personally find Tiles to be powerful but given the elapsed time, I was expecting something new to replace it. Why Tiles may not be so appropriate these days? It relies on JSPs which are not trivial to test outside a web container. The tiles XML where definitions go, is very similar to a Spring beans file. Nowadays you could expect a n...

Websites about using JPA 2.0 with Google app engine

Maven archetype to generate project (found by googling maven jpa 2 google app engine Archetype ): http://webapplicationdeveloper.blogspot.co.uk/2012/07/google-datastore-with-jpa-and-spring.html For Maven and Google App Engine, see also: http://code.google.com/p/maven-gae-plugin/ Google App engine documentation about JPA 2 support: https://developers.google.com/appengine/docs/java/datastore/jpa/overview-dn2 Google App engine documentation about the java datastore: https://developers.google.com/appengine/docs/java/gettingstarted/usingdatastore Another cool article but not to JPA or google app engine: https://code.google.com/p/guava-libraries/wiki/CachesExplained