AO
const reloadTable$ = new Subject<void>();Size: a a a
AO
const reloadTable$ = new Subject<void>();ОС
AO
periodService.addPeriod(...).pipe(...).subscribe(() => this.reloadTable$.next());AO
@Input(), смысла ngOnInit нет) выстроить цепочку реакции:this.reloadTrigger$.pipe(
startWith(), // запуск первого запроса при инициализации все равно нужен
switchMap(() => this.periodService.getPeriodList()),
...
takeUntil(this._destroy),
).subscribe(...)
AO
subscribe блоку тоже много вопросов, потому что в нем присваиваются значения переменным. Почему бы не вынести все в async pipe?this.loginService.dateClosedPeriod = нарушает бест практис. Это получается, что Компонент присваивает значение у сервиса на прямую!AO
AO
ViewModel в виде Обзервабл.AO
readonly vm$: Observable<{tableData: Data, status: LoadingStatus, error: string}>AO
AO
this.reloadTrigger$.pipe(
startWith(), // запуск первого запроса при инициализации все равно нужен
tap(() => {
this.loading = true
}),
switchMap(() => this.periodService.getPeriodList().pipe(
tap(() => {
// это не должно здесь жить, но хотя бы переделай в функцию
this.loginService.setClose(new Date(data.maxPeriod));
}),
// inner Observable pipe, so that it doesn't collapse the outer stream on error
map(data => {
const periodList = data.response;
// тут все подсчеты можно сделать - это будет pure function, вне класса компонента (можно в том же файле)
const periods = calculatePeriods(data);
return {
...periods, // тут все твои dateStartPeriod и т.д.
periodList
};
}),
// handles both complete (it's a one-time Observable) and error cases
finalize(() => this.loading = false),
// do not let the error go through
catchError(() => EMPTY),
),
takeUntil(this.destroy), // это уже в outer Observable pipe
).subscribe();
AO
subscribe, можно сделать this.vm$ = this.reloadTrigger$.pipe(...)ОС
this.reloadTrigger$.pipe(
startWith(), // запуск первого запроса при инициализации все равно нужен
tap(() => {
this.loading = true
}),
switchMap(() => this.periodService.getPeriodList().pipe(
tap(() => {
// это не должно здесь жить, но хотя бы переделай в функцию
this.loginService.setClose(new Date(data.maxPeriod));
}),
// inner Observable pipe, so that it doesn't collapse the outer stream on error
map(data => {
const periodList = data.response;
// тут все подсчеты можно сделать - это будет pure function, вне класса компонента (можно в том же файле)
const periods = calculatePeriods(data);
return {
...periods, // тут все твои dateStartPeriod и т.д.
periodList
};
}),
// handles both complete (it's a one-time Observable) and error cases
finalize(() => this.loading = false),
// do not let the error go through
catchError(() => EMPTY),
),
takeUntil(this.destroy), // это уже в outer Observable pipe
).subscribe();
ОС
subscribe блоку тоже много вопросов, потому что в нем присваиваются значения переменным. Почему бы не вынести все в async pipe?this.loginService.dateClosedPeriod = нарушает бест практис. Это получается, что Компонент присваивает значение у сервиса на прямую!ОС
this.reloadTrigger$.pipe(
startWith(), // запуск первого запроса при инициализации все равно нужен
tap(() => {
this.loading = true
}),
switchMap(() => this.periodService.getPeriodList().pipe(
tap(() => {
// это не должно здесь жить, но хотя бы переделай в функцию
this.loginService.setClose(new Date(data.maxPeriod));
}),
// inner Observable pipe, so that it doesn't collapse the outer stream on error
map(data => {
const periodList = data.response;
// тут все подсчеты можно сделать - это будет pure function, вне класса компонента (можно в том же файле)
const periods = calculatePeriods(data);
return {
...periods, // тут все твои dateStartPeriod и т.д.
periodList
};
}),
// handles both complete (it's a one-time Observable) and error cases
finalize(() => this.loading = false),
// do not let the error go through
catchError(() => EMPTY),
),
takeUntil(this.destroy), // это уже в outer Observable pipe
).subscribe();
async pipe. Правильно я понял?AO
AO
async pipe. Правильно я понял?vm$ - вместо takeUntil + subscribe() пустой, теперь можно просто в темплейт с async вынестиAO
ОС
ОС
this.reloadTrigger$.pipe(
startWith(), // запуск первого запроса при инициализации все равно нужен
tap(() => {
this.loading = true
}),
switchMap(() => this.periodService.getPeriodList().pipe(
tap(() => {
// это не должно здесь жить, но хотя бы переделай в функцию
this.loginService.setClose(new Date(data.maxPeriod));
}),
// inner Observable pipe, so that it doesn't collapse the outer stream on error
map(data => {
const periodList = data.response;
// тут все подсчеты можно сделать - это будет pure function, вне класса компонента (можно в том же файле)
const periods = calculatePeriods(data);
return {
...periods, // тут все твои dateStartPeriod и т.д.
periodList
};
}),
// handles both complete (it's a one-time Observable) and error cases
finalize(() => this.loading = false),
// do not let the error go through
catchError(() => EMPTY),
),
takeUntil(this.destroy), // это уже в outer Observable pipe
).subscribe();
periodService.addPeriod(...).pipe(...).subscribe(() => this.reloadTrigger$.next());. Правильно я понял?AO
periodService.addPeriod(...).pipe(...).subscribe(() => this.reloadTrigger$.next());. Правильно я понял?