refactor: improve observable layout change sharing

This commit is contained in:
sashaqred 2020-04-15 11:42:52 +03:00 committed by Maksim Karatkevich
parent b4b07f7e82
commit 2d75441977

View file

@ -0,0 +1,20 @@
import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { delay, shareReplay } from 'rxjs/operators';
@Injectable()
export class LayoutService {
protected layoutSize$ = new Subject();
protected layoutSizeChange$ = this.layoutSize$.pipe(
shareReplay({ refCount: true }),
);
changeLayoutSize() {
this.layoutSize$.next();
}
onChangeLayoutSize(): Observable<any> {
return this.layoutSizeChange$.pipe(delay(1));
}
}