From 0c198986940e47f783fa1f512bb565459f83091c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Thu, 15 Dec 2016 14:18:57 -0800 Subject: [PATCH] fix(animations): allow players to be destroyed before initialized (#13346) Closes #13293 Closes #13346 --- .../platform-browser/src/dom/web_animations_player.ts | 6 +++++- .../platform-browser/test/dom/web_animations_player_spec.ts | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/@angular/platform-browser/src/dom/web_animations_player.ts b/modules/@angular/platform-browser/src/dom/web_animations_player.ts index 627a8055c6..ddd53e72a1 100644 --- a/modules/@angular/platform-browser/src/dom/web_animations_player.ts +++ b/modules/@angular/platform-browser/src/dom/web_animations_player.ts @@ -124,7 +124,11 @@ export class WebAnimationsPlayer implements AnimationPlayer { this._started = false; } - private _resetDomPlayerState() { this._player.cancel(); } + private _resetDomPlayerState() { + if (this._player) { + this._player.cancel(); + } + } restart(): void { this.reset(); diff --git a/modules/@angular/platform-browser/test/dom/web_animations_player_spec.ts b/modules/@angular/platform-browser/test/dom/web_animations_player_spec.ts index 8072279501..7bba7ed96d 100644 --- a/modules/@angular/platform-browser/test/dom/web_animations_player_spec.ts +++ b/modules/@angular/platform-browser/test/dom/web_animations_player_spec.ts @@ -175,6 +175,12 @@ export function main() { expect(data['keyframes']).toEqual([{opacity: '0.5'}, {opacity: '1'}]); }); + it('should allow the player to be destroyed before it is initialized', () => { + const elm = el('
'); + const player = new ExtendedWebAnimationsPlayer(elm, [], {}); + expect(() => { player.destroy(); }).not.toThrowError(); + }); + describe('previousStyle', () => { it('should merge keyframe styles based on the previous styles passed in when the player has finished its operation', () => {