Created
August 21, 2019 22:52
-
-
Save timjonesdev/51a0f02a4dba6778f10a37344d1978da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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