The of () operator essentially converted a list of arguments to an Observable. Since arrays is often how we structure the list of things in JavaScript, we should has a-to transforming arrays into Obs Ervables. This lesson teaches how can I convert from Arrays to observables, from Promises to Observables, and from iterators to Ob Servables.
Formarray:
varary = [1,2,3];varFoo =Rx.Observable.fromArray (ary); Foo.subscribe (function (x) {Console.log ('Next'+x);}, function (err) {Console.log ('Error'+err);}, function () {Console.log (' Done');});/*"Next 1" "Next 2" "Next 3" "Done"*/
Frompromise:
varProm = Fetch ('https://null.jsbin.com');varFoo =Rx.Observable.fromPromise (Prom); Foo.subscribe (function (x) {Console.log ('Next'+x.status);}, function (err) {Console.log ('Error'+err);}, function () {Console.log (' Done');});/*"Next 204 " "Done"*/
From
From () Opreator can-create observalbes according-to-you-passed in
=fromarray:
varary = [1,2,3];varFoo = rx.observable. from(ary); Foo.subscribe (function (x) {Console.log ('Next'+x);}, function (err) {Console.log ('Error'+err);}, function () {Console.log (' Done');});/*"Next 1" "Next 2" "Next 3" "Done"*/
=frompromiose
var foo = rx.observable. from (Prom); Foo.subscribe (function (x) { console.log (' + x.status);}, function (err) { console.log (' + err);}, function () { Console.log ('done');});
From iterator:
function*Generator () {yield Ten; yield -; yield -;}variterator =generator ();varFoo = rx.observable. from(iterator); Foo.subscribe (function (x) {Console.log ('Next'+x);}, function (err) {Console.log ('Error'+err);}, function () {Console.log (' Done');});/*"Next" "Next" "Next" "Done "*/
[RxJS] Creation operators:from, FromArray, frompromise