I have asked this in the gitter room, but there were no responses, so I thought I might ask this here.
It looks like if we want to work with Rx.Observables, we'll have to use the EventEmitter class.
I was wondering how to do the following:
- My component calls a service passing something by parameter;
- My service modifies the parameter;
- My service returns an Observables so that my Component can observe and subscribe to it;
If I am using Rx.Observable (by importing it directly - import * as Rx from 'rx'), I can do the following:
// MyService
export class MyService {
static doSomething(something: Object):Rx.Observable {
return Rx.Observable.create(o => {
something.createdAt = Date.now();
o.onNext(something);
o.onCompleted();
})
}
}
And then in my component:
// MyComponent
class MyComponent {
doSomethingHandler(something:Object):void {
MyService.doSomething(something).subscribe(info => console.log(info));
}
}
So, that'd work.
But how to do it with the EventEmitter wrapper?
I saw it returns a Subject instead of an Observable, and it looks like I'd have to pass callbacks left and right to make it work - but I'd like to have the logic separated - having the component to only call the service, and this one would do the heavy work, returning something already manipulated to the component.
I have asked this in the gitter room, but there were no responses, so I thought I might ask this here.
It looks like if we want to work with Rx.Observables, we'll have to use the EventEmitter class.
I was wondering how to do the following:
If I am using Rx.Observable (by importing it directly -
import * as Rx from 'rx'), I can do the following:And then in my component:
So, that'd work.
But how to do it with the EventEmitter wrapper?
I saw it returns a
Subjectinstead of anObservable, and it looks like I'd have to pass callbacks left and right to make it work - but I'd like to have the logic separated - having the component to only call the service, and this one would do the heavy work, returning something already manipulated to the component.