Skip to content

Instantly share code, notes, and snippets.

@timjonesdev
Created August 21, 2019 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timjonesdev/51a0f02a4dba6778f10a37344d1978da to your computer and use it in GitHub Desktop.
Save timjonesdev/51a0f02a4dba6778f10a37344d1978da to your computer and use it in GitHub Desktop.
export class MatchupComponent implements OnInit {
teams: TeamModel[] = [];
constructor(private teamService: TeamService) {
}
ngOnInit() {
this.loadTeams();
}
/**
* Subscribe to the necessary backend data services
*/
private loadTeams(): void {
// subscribe to initial set of teams
this.teamService._teamsSource.subscribe(value => {
if (value !== undefined && value !== null) {
this.teams = [].concat(value);
}
});
// subscribe to changes in player team scores and player values
this.teamService._teamWatchSource.subscribe(updatedTeam => {
if (updatedTeam !== undefined && updatedTeam.name !== undefined) {
let name = updatedTeam.name;
let length = this.teams.length;
for (let i = 0; i < length; i++) {
if (this.teams[i].name === name) {
this.teams[i] = updatedTeam;
}
}
// trick to get the Angular event loop to pick up changes to array
this.teams = [].concat(this.teams);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment