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);
}
}
}
}

View File

@ -29,19 +29,19 @@ export class AnimationViewContext {
queueAnimation(element: any, animationName: string, player: AnimationPlayer): void {
queueAnimationGlobally(player);
this._players.set(element, animationName, player);
player.onDone(() => this._players.remove(element, animationName, player));
}
getAnimationPlayers(element: any, animationName: string, removeAllAnimations: boolean = false):
AnimationPlayer[] {
getAnimationPlayers(element: any, animationName: string = null): AnimationPlayer[] {
const players: AnimationPlayer[] = [];
if (removeAllAnimations) {
this._players.findAllPlayersByElement(element).forEach(
player => { _recursePlayers(player, players); });
} else {
if (animationName) {
const currentPlayer = this._players.find(element, animationName);
if (currentPlayer) {
_recursePlayers(currentPlayer, players);
}
} else {
this._players.findAllPlayersByElement(element).forEach(
player => _recursePlayers(player, players));
}
return players;
}