I have cloned one Github repo based on RXJS with angular 2+. Help me understand the meaning of this.createTodo$.subscribe(this.create$) in below code.
I am able to understand that here we are trying to subscribe createTodo$ observable.Inside the subscribe method I always set data but what does this.create$ means.Here create$ is a Subject.
Please find the service code where this subscription is made.
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable ,Subject} from 'rxjs';
import { itemmodel } from './models/listmodel';
import {scan,map} from 'rxjs/operators';
type TodosOperation = (todos: itemmodel[]) => itemmodel[];
const initialTodos=[];
@Injectable({
providedIn: 'root'
})
export class SharedserviceService {
public data;
create$: Subject<itemmodel> = new Subject<itemmodel>();
createTodo$: Subject<itemmodel> = new Subject<itemmodel>();
todos$:Observable<itemmodel[]>;
public item = new BehaviorSubject([]);
update$: BehaviorSubject<TodosOperation> = new BehaviorSubject<TodosOperation>((todos: itemmodel[]) => todos);
constructor(){
this.todos$ = this.update$.pipe(scan((todos: itemmodel[], operation: TodosOperation) => operation(todos), initialTodos));
this.create$.pipe(map((todo) => {
return (todos) => todos.concat(todo);
})).subscribe(this.update$);
this.createTodo$.subscribe(this.create$);
}
public additem(item){
this.createTodo$.next(item);
}
}