MOBILE-3814 network: Improve network observable performance

main
Pau Ferrer Ocaña 2022-03-15 10:13:21 +01:00
parent 0d01449393
commit 39937e2252
3 changed files with 20 additions and 21 deletions

View File

@ -24,6 +24,9 @@ export class NetworkMock extends Network {
type!: string; type!: string;
protected connectObservable = new Subject<'connected'>();
protected disconnectObservable = new Subject<'disconnected'>();
constructor() { constructor() {
super(); super();
@ -38,6 +41,14 @@ export class NetworkMock extends Network {
CELL: 'cellular', // eslint-disable-line @typescript-eslint/naming-convention CELL: 'cellular', // eslint-disable-line @typescript-eslint/naming-convention
NONE: 'none', // eslint-disable-line @typescript-eslint/naming-convention NONE: 'none', // eslint-disable-line @typescript-eslint/naming-convention
}; };
window.addEventListener('online', () => {
this.connectObservable.next('connected');
}, false);
window.addEventListener('offline', () => {
this.disconnectObservable.next('disconnected');
}, false);
} }
/** /**
@ -45,8 +56,8 @@ export class NetworkMock extends Network {
* *
* @return Observable. * @return Observable.
*/ */
onchange(): Observable<unknown> { onChange(): Observable<'connected' | 'disconnected'> {
return merge(this.onConnect(), this.onDisconnect()); return merge(this.connectObservable, this.disconnectObservable);
} }
/** /**
@ -54,14 +65,8 @@ export class NetworkMock extends Network {
* *
* @return Observable. * @return Observable.
*/ */
onConnect(): Observable<unknown> { onConnect(): Observable<'connected'> {
const observable = new Subject<unknown>(); return this.connectObservable;
window.addEventListener('online', (ev) => {
observable.next(ev);
}, false);
return observable;
} }
/** /**
@ -69,14 +74,8 @@ export class NetworkMock extends Network {
* *
* @return Observable. * @return Observable.
*/ */
onDisconnect(): Observable<unknown> { onDisconnect(): Observable<'disconnected'> {
const observable = new Subject<unknown>(); return this.disconnectObservable;
window.addEventListener('offline', (ev) => {
observable.next(ev);
}, false);
return observable;
} }
} }

View File

@ -168,11 +168,11 @@ ion-tabs.placement-side {
opacity: .8; opacity: .8;
z-index: 12; z-index: 12;
.core-online { .core-online-message {
display: var(--network-message-online); display: var(--network-message-online);
} }
.core-offline { .core-offline-message {
display: var(--network-message-offline); display: var(--network-message-offline);
} }
} }

View File

@ -22,5 +22,5 @@ export default async function(): Promise<void> {
} }
await Platform.ready(); await Platform.ready();
await CoreIframeUtils.injectiOSScripts(window); CoreIframeUtils.injectiOSScripts(window);
} }