fix(animations): always cleanup players after they have finished internally (#13334)

Closes #13333
Closes #13334
This commit is contained in:
Matias Niemelä
2016-12-09 10:45:10 -08:00
committed by Victor Berchet
parent c0b001a6af
commit a26e054857
5 changed files with 114 additions and 13 deletions

View File

@ -44,16 +44,18 @@ export class ViewAnimationMap {
getAllPlayers(): AnimationPlayer[] { return this._allPlayers; }
remove(element: any, animationName: string): void {
remove(element: any, animationName: string, targetPlayer: AnimationPlayer = null): void {
const playersByAnimation = this._map.get(element);
if (playersByAnimation) {
const player = playersByAnimation[animationName];
delete playersByAnimation[animationName];
const index = this._allPlayers.indexOf(player);
this._allPlayers.splice(index, 1);
if (!targetPlayer || player === targetPlayer) {
delete playersByAnimation[animationName];
const index = this._allPlayers.indexOf(player);
this._allPlayers.splice(index, 1);
if (Object.keys(playersByAnimation).length === 0) {
this._map.delete(element);
if (Object.keys(playersByAnimation).length === 0) {
this._map.delete(element);
}
}
}
}