Skip to content

Commit

Permalink
Fix navbar update speed on identity-change
Browse files Browse the repository at this point in the history
  • Loading branch information
yusufsallam64 committed Sep 2, 2023
1 parent 3a703b7 commit efeafc0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/elements/common/navbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { GameFull } from '@rivet-gg/cloud';
import assets from '../../data/assets';
import { ifDefined } from 'lit/directives/if-defined.js';
import { CloudGameCache, GroupProfileCache } from '../../data/cache';
import { globalEventGroups, IdentityChangeEvent } from '../../utils/global-events';

export type Breadcrumb =
| { type: 'Home' }
Expand Down Expand Up @@ -48,6 +49,20 @@ export default class NavBar extends LitElement {
groupStream: api.RepeatingRequest<api.group.GetGroupProfileCommandOutput> = null;
gameStream?: api.RepeatingRequest<cloud.GetGameByIdCommandOutput>;

/// === EVENTS ===
handleIdentityChange: (e: IdentityChangeEvent) => void;

connectedCallback() {
super.connectedCallback();

this.handleIdentityChange = this.onIdentityChange.bind(this);
globalEventGroups.add('identity-change', this.handleIdentityChange);
}

onIdentityChange() {
this.requestUpdate();
}

updated(changedProperties: PropertyValues) {
super.updated(changedProperties);

Expand All @@ -60,6 +75,8 @@ export default class NavBar extends LitElement {
disconnectedCallback() {
super.disconnectedCallback();

globalEventGroups.remove('identity-change', this.handleIdentityChange);

if (this.groupStream) this.groupStream.cancel();
if (this.gameStream) this.gameStream.cancel();
}
Expand Down

0 comments on commit efeafc0

Please sign in to comment.