Skip to content

Instantly share code, notes, and snippets.

@mcgill-a
Created September 25, 2023 12:51
Show Gist options
  • Save mcgill-a/7f92a1d32fed02b5dd4541ba53483aed to your computer and use it in GitHub Desktop.
Save mcgill-a/7f92a1d32fed02b5dd4541ba53483aed to your computer and use it in GitHub Desktop.
A minimal frontend service for updating user data in Angular
@Injectable({ providedIn: 'root' })
constructor(private socketService: SocketService) {
this.subs.add(
this.socketService.userChange.subscribe((change: UserChange) => {
const {user, action} = change;
switch (change.action) {
case UserAction.join:
case TeamAction.position:
this._users.set(user.email, user);
break;
case UserAction.leave:
this._users.delete(user.email);
break;
})
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment