Working with RxJS in Angular 4.x, I'm seeing two very different patterns for generating Observables from streams of user initiated actions. One stream is the direct result of a user clicking an 'add item' button that generates a new object. The other is a series of events issued by some third party code I'm using.
I want to be able to combine these two streams using something like 'combineLatest' to generate a single Observable.
With my button, I've followed the following pattern:
const signal = Observable.create(
(observer) => {
this.additem= (item) => observer.next(item);
}
);
this.item$ = signal.map((item) => [item])
.scan((accumulator, value) => {
return accumulator.concat(value);
});
However, I'm seeing a lot of information saying I should be using Subjects instead - which I am trying to use with my event callback like so:
sort$ = new Subject();
sortChange(sort){
sort$.next(sort);
}
Then I'm attempting to combine these like this:
combine$ = Observable.combineLatest(sort$, item$,
(sort, items) => {
return "something that does stuff with these";}
);
My questions are - what is the preferred pattern for 'manually' generating streams? Can/should observables and subjects be meshed together into a single observable like I'm trying to do here?