Is there a reason why we cannot create an Observable from an object?
It was possible before using Observable.of, but now with from it doesn't seem possible anymore ?
Would you able to share small snippet to describe issues you're experiencing?
On second thought, this might be a problem with me using RxJS alpha 11 (because of Angular 2 currently locked down to this version) and being unable to use Observable.of
Are .of & .from different ?
Are .of & .from different ?
: sort of.
Observable.from = FromObservable.create;
and
Observable.of = ArrayObservable.of;
currently. (Latest tot of RxJS5 at least).
Ok, so there's no way to use ArrayObservable.of on an Object (that is not an array) then ?
I still would like to ask usecases you're trying, in typical usecases I didn't see it's blocking my usage for instance
Observable.of(1).subscribe(console.log)
would work. Curious what object you're trying to pass.
Curious what object you're trying to pass.
: reason that it might have some of bugs couldn't be caught until. :)
Sure, the code (just updated) is here: https://github.com/ocombe/ng2-translate/blob/master/src/translate.service.ts#L112
I'm returning an observable that can something be pending (because of an http request), and sometimes resolve immediately once the request has been made at least once (or when it's not pending).
The observable can be made of a promise, or the actual object return by the http request.
But I won't use a Promise here because you can change the lang and it will make a new http request
@ocombe
from accepts any Iterable (Arrays, Strings, Generators, Custom Iteratables, etc), Promise, Observable, or "lowercase o" observable.
of takes a bunch of values and makes them into an Observable of those values.
If you want to observe an arbitrary object, that object needs to implement Symbol.observable and return a (lowercase "o") observable. That is an object with a subscribe method that accepts an observer.
I don't want to observe the object, I just need to return an observable what ever the status of my request is.
It's well explained in http://reactivex.io/documentation/operators/from.html :
When you work with Observables, it can be more convenient if all of the data you mean to work with can be represented as Observables, rather than as a mixture of Observables and other types. This allows you to use a single set of operators to govern the entire lifespan of the data stream.
@ocombe it's a little hard to follow the code you sent because it's very heavily abstracted. Perhaps it would be valuable to reduce the abstraction until you get it working, then factor your code out as necessary for testing? FWIW: Angular2's http.request() should just return an Observable<Response>
Observable.of will be a completely synchronous observable of whatever value you give it.
Observable.from converts from some type (Promise, Array, Iterable, Observable, lowercase-o observable) to an Rx.Observable.
Yeah that's why I used the ArrayObservable.of in the end, and it works fine, it's just weird to have use something called ArrayObservable to make an Observable from any static value that is not always an array.
something called ArrayObservable to make an Observable from any static value that is not always an array.
: Any reason for not using Observable.of? it's for generic interface for values.
It's not available on alpha 11 and Angular 2 is locked down on this version for now, I'll switch to that once they update their dependencies :-)
Thanks for the explanations anyway, I'll close this issue since it's not really an issue.
By the way, it would be really nice to have documentation for this project, the current docs in the repo are really really light when they are available at all (all the links on https://github.com/ReactiveX/RxJS/blob/master/doc/index.md are 404)
For document, totally agree. That's one of milestone should be achieved we're trying to push for.
:+1:
@ocombe what is the equivalent for the Observable.of in the recent version of rxjs. I'm using version 5.5.5
import {of} from "rxjs/observable/of";
https://github.com/ngx-translate/core/blob/master/lib/src/translate.service.ts#L11
@aravindfz Observable.of will still work. We didn't remove rxjs/add/observable/of... not even in the v6 alpha.
But in ALL versions of 5.x you can import from import { of } from 'rxjs/observable/of', it's nothing new to 5.5, it's just that word didn't get out that this is probably better until then.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Observable.ofwill be a completely synchronous observable of whatever value you give it.Observable.fromconverts from some type (Promise, Array, Iterable, Observable, lowercase-o observable) to an Rx.Observable.