O'Reilly logo

Mastering Reactive JavaScript by Erich de Souza Oliveira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating an observable from a sequence factory

Now that we have discussed how to create an observable from a sequence, let's see how we can create an observable from a sequence factory. RxJS has a built-in method called generate() that lets you create an observable from an iteration (such as a for() loop). This method has the following signature:

Rx.Observable.generate(initialState, conditionFunction, iterationFunction, resultFactory, [scheduler]); 

In this method, the only optional parameter is the last one. A brief description of all the parameters is as follows:

  • initialState: This can be any object, it is the first object used in the iteration
  • conditionFunction: This is a function with the condition to stop the iteration
  • iterationFunction ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required