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;
protected connectObservable = new Subject<'connected'>();
protected disconnectObservable = new Subject<'disconnected'>();
constructor() {
super();
@ -38,6 +41,14 @@ export class NetworkMock extends Network {
CELL: 'cellular', // 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.
*/
onchange(): Observable<unknown> {
return merge(this.onConnect(), this.onDisconnect());
onChange(): Observable<'connected' | 'disconnected'> {
return merge(this.connectObservable, this.disconnectObservable);
}
/**
@ -54,14 +65,8 @@ export class NetworkMock extends Network {
*
* @return Observable.
*/
onConnect(): Observable<unknown> {
const observable = new Subject<unknown>();
window.addEventListener('online', (ev) => {
observable.next(ev);
}, false);
return observable;
onConnect(): Observable<'connected'> {
return this.connectObservable;
}
/**
@ -69,14 +74,8 @@ export class NetworkMock extends Network {
*
* @return Observable.
*/
onDisconnect(): Observable<unknown> {
const observable = new Subject<unknown>();
window.addEventListener('offline', (ev) => {
observable.next(ev);
}, false);
return observable;
onDisconnect(): Observable<'disconnected'> {
return this.disconnectObservable;
}
}

View File

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

View File

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