I try to get an observable of the window innerWidth.
I set a fromEvent observable watching on resize event
public get nativeWindow(): Window {
return window;
}
public getWindowSize(): Observable<number> {
return fromEvent(this.nativeWindow, 'resize').pipe(
map(event => (event.target as Window).innerWidth)
);
}
I want to be able to get the initial value of window.innerWidth because resize won't fire until actual window resize.
I could use BehaviorSubject but it forces me to subscribe to fromEvent to next on the subject.
We tried use a startWith(this.nativeWindow.innerWidth) operator before the map but the map then doesn't get the event argument as Event but get the startWith number instead.
Is there any rxjs operator which could allow me initialize first number before getting actual resize events?