Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions modules/@angular/compiler/src/animation/animation_compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,17 +251,22 @@ class _AnimationBuilder implements AnimationAstVisitor {
_ANIMATION_PLAYER_VAR
.callMethod(
'onDone',
[o.fn(
[],
[RENDER_STYLES_FN
.callFn([
_ANIMATION_FACTORY_ELEMENT_VAR, _ANIMATION_FACTORY_RENDERER_VAR,
o.importExpr(resolveIdentifier(Identifiers.prepareFinalAnimationStyles))
[o
.fn([],
[
_ANIMATION_PLAYER_VAR.callMethod('destroy', []).toStmt(),
RENDER_STYLES_FN
.callFn([
_ANIMATION_START_STATE_STYLES_VAR, _ANIMATION_END_STATE_STYLES_VAR
_ANIMATION_FACTORY_ELEMENT_VAR, _ANIMATION_FACTORY_RENDERER_VAR,
o.importExpr(
resolveIdentifier(Identifiers.prepareFinalAnimationStyles))
.callFn([
_ANIMATION_START_STATE_STYLES_VAR,
_ANIMATION_END_STATE_STYLES_VAR
])
])
])
.toStmt()])])
.toStmt()
])])
.toStmt());

statements.push(_ANIMATION_FACTORY_VIEW_CONTEXT
Expand Down
18 changes: 12 additions & 6 deletions modules/@angular/core/src/animation/animation_group_player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class AnimationGroupPlayer implements AnimationPlayer {
private _onStartFns: Function[] = [];
private _finished = false;
private _started = false;
private _destroyed = false;

public parentPlayer: AnimationPlayer = null;

Expand All @@ -38,9 +39,6 @@ export class AnimationGroupPlayer implements AnimationPlayer {
private _onFinish() {
if (!this._finished) {
this._finished = true;
if (!isPresent(this.parentPlayer)) {
this.destroy();
}
this._onDoneFns.forEach(fn => fn());
this._onDoneFns = [];
}
Expand Down Expand Up @@ -76,11 +74,19 @@ export class AnimationGroupPlayer implements AnimationPlayer {
}

destroy(): void {
this._onFinish();
this._players.forEach(player => player.destroy());
if (!this._destroyed) {
this._onFinish();
this._players.forEach(player => player.destroy());
this._destroyed = true;
}
}

reset(): void { this._players.forEach(player => player.reset()); }
reset(): void {
this._players.forEach(player => player.reset());
this._destroyed = false;
this._finished = false;
this._started = false;
}

setPosition(p: any /** TODO #9100 */): void {
this._players.forEach(player => { player.setPosition(p); });
Expand Down
22 changes: 14 additions & 8 deletions modules/@angular/core/src/animation/animation_sequence_player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export class AnimationSequencePlayer implements AnimationPlayer {
private _onDoneFns: Function[] = [];
private _onStartFns: Function[] = [];
private _finished = false;
private _started: boolean = false;
private _started = false;
private _destroyed = false;

public parentPlayer: AnimationPlayer = null;

Expand Down Expand Up @@ -48,9 +49,6 @@ export class AnimationSequencePlayer implements AnimationPlayer {
private _onFinish() {
if (!this._finished) {
this._finished = true;
if (!isPresent(this.parentPlayer)) {
this.destroy();
}
this._onDoneFns.forEach(fn => fn());
this._onDoneFns = [];
}
Expand Down Expand Up @@ -79,22 +77,30 @@ export class AnimationSequencePlayer implements AnimationPlayer {
pause(): void { this._activePlayer.pause(); }

restart(): void {
this.reset();
if (this._players.length > 0) {
this.reset();
this._players[0].restart();
}
}

reset(): void { this._players.forEach(player => player.reset()); }
reset(): void {
this._players.forEach(player => player.reset());
this._destroyed = false;
this._finished = false;
this._started = false;
}

finish(): void {
this._onFinish();
this._players.forEach(player => player.finish());
}

destroy(): void {
this._onFinish();
this._players.forEach(player => player.destroy());
if (!this._destroyed) {
this._onFinish();
this._players.forEach(player => player.destroy());
this._destroyed = true;
}
}

setPosition(p: any /** TODO #9100 */): void { this._players[0].setPosition(p); }
Expand Down
87 changes: 47 additions & 40 deletions modules/@angular/core/test/animation/animation_group_player_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function main() {
assertLastStatus(players[2], 'restart', true);
});

it('should finish all the players', () => {
it('should not destroy the inner the players when finished', () => {
var group = new AnimationGroupPlayer(players);

var completed = false;
Expand All @@ -113,55 +113,36 @@ export function main() {

group.finish();

assertLastStatus(players[0], 'finish', true, -1);
assertLastStatus(players[1], 'finish', true, -1);
assertLastStatus(players[2], 'finish', true, -1);

assertLastStatus(players[0], 'destroy', true);
assertLastStatus(players[1], 'destroy', true);
assertLastStatus(players[2], 'destroy', true);
assertLastStatus(players[0], 'finish', true);
assertLastStatus(players[1], 'finish', true);
assertLastStatus(players[2], 'finish', true);

expect(completed).toBeTruthy();
});

it('should call destroy automatically when finished if no parent player is present', () => {
var group = new AnimationGroupPlayer(players);
it('should not call destroy automatically when finished even if a parent player finishes',
() => {
var group = new AnimationGroupPlayer(players);
var parent = new AnimationGroupPlayer([group, new MockAnimationPlayer()]);

group.play();
group.play();

assertLastStatus(players[0], 'destroy', false);
assertLastStatus(players[1], 'destroy', false);
assertLastStatus(players[2], 'destroy', false);
assertLastStatus(players[0], 'destroy', false);
assertLastStatus(players[1], 'destroy', false);
assertLastStatus(players[2], 'destroy', false);

group.finish();
group.finish();

assertLastStatus(players[0], 'destroy', true);
assertLastStatus(players[1], 'destroy', true);
assertLastStatus(players[2], 'destroy', true);
});
assertLastStatus(players[0], 'destroy', false);
assertLastStatus(players[1], 'destroy', false);
assertLastStatus(players[2], 'destroy', false);

it('should not call destroy automatically when finished if a parent player is present', () => {
var group = new AnimationGroupPlayer(players);
var parent = new AnimationGroupPlayer([group, new MockAnimationPlayer()]);

group.play();

assertLastStatus(players[0], 'destroy', false);
assertLastStatus(players[1], 'destroy', false);
assertLastStatus(players[2], 'destroy', false);

group.finish();
parent.finish();

assertLastStatus(players[0], 'destroy', false);
assertLastStatus(players[1], 'destroy', false);
assertLastStatus(players[2], 'destroy', false);

parent.finish();

assertLastStatus(players[0], 'destroy', true);
assertLastStatus(players[1], 'destroy', true);
assertLastStatus(players[2], 'destroy', true);
});
assertLastStatus(players[0], 'destroy', false);
assertLastStatus(players[1], 'destroy', false);
assertLastStatus(players[2], 'destroy', false);
});

it('should function without any players', () => {
var group = new AnimationGroupPlayer([]);
Expand Down Expand Up @@ -193,5 +174,31 @@ export function main() {
flushMicrotasks();
expect(completed).toEqual(true);
}));

it('should not allow the player to be destroyed if it already has been destroyed unless reset',
fakeAsync(() => {
var p1 = new MockAnimationPlayer();
var p2 = new MockAnimationPlayer();
var innerPlayers = [p1, p2];

var groupPlayer = new AnimationGroupPlayer(innerPlayers);
expect(p1.log[p1.log.length - 1]).not.toContain('destroy');
expect(p2.log[p2.log.length - 1]).not.toContain('destroy');

groupPlayer.destroy();
expect(p1.log[p1.log.length - 1]).toContain('destroy');
expect(p2.log[p2.log.length - 1]).toContain('destroy');

p1.log = p2.log = [];

groupPlayer.destroy();
expect(p1.log[p1.log.length - 1]).not.toContain('destroy');
expect(p2.log[p2.log.length - 1]).not.toContain('destroy');

groupPlayer.reset();
groupPlayer.destroy();
expect(p1.log[p1.log.length - 1]).toContain('destroy');
expect(p2.log[p2.log.length - 1]).toContain('destroy');
}));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,55 +135,36 @@ export function main() {

sequence.finish();

assertLastStatus(players[0], 'finish', true, -1);
assertLastStatus(players[1], 'finish', true, -1);
assertLastStatus(players[2], 'finish', true, -1);

assertLastStatus(players[0], 'destroy', true);
assertLastStatus(players[1], 'destroy', true);
assertLastStatus(players[2], 'destroy', true);
assertLastStatus(players[0], 'finish', true);
assertLastStatus(players[1], 'finish', true);
assertLastStatus(players[2], 'finish', true);

expect(completed).toBeTruthy();
});

it('should call destroy automatically when finished if no parent player is present', () => {
var sequence = new AnimationSequencePlayer(players);
it('should not call destroy automatically when finished even if a parent player is present',
() => {
var sequence = new AnimationSequencePlayer(players);
var parent = new AnimationSequencePlayer([sequence, new MockAnimationPlayer()]);

sequence.play();
sequence.play();

assertLastStatus(players[0], 'destroy', false);
assertLastStatus(players[1], 'destroy', false);
assertLastStatus(players[2], 'destroy', false);
assertLastStatus(players[0], 'destroy', false);
assertLastStatus(players[1], 'destroy', false);
assertLastStatus(players[2], 'destroy', false);

sequence.finish();
sequence.finish();

assertLastStatus(players[0], 'destroy', true);
assertLastStatus(players[1], 'destroy', true);
assertLastStatus(players[2], 'destroy', true);
});
assertLastStatus(players[0], 'destroy', false);
assertLastStatus(players[1], 'destroy', false);
assertLastStatus(players[2], 'destroy', false);

it('should not call destroy automatically when finished if a parent player is present', () => {
var sequence = new AnimationSequencePlayer(players);
var parent = new AnimationSequencePlayer([sequence, new MockAnimationPlayer()]);

sequence.play();

assertLastStatus(players[0], 'destroy', false);
assertLastStatus(players[1], 'destroy', false);
assertLastStatus(players[2], 'destroy', false);

sequence.finish();
parent.finish();

assertLastStatus(players[0], 'destroy', false);
assertLastStatus(players[1], 'destroy', false);
assertLastStatus(players[2], 'destroy', false);

parent.finish();

assertLastStatus(players[0], 'destroy', true);
assertLastStatus(players[1], 'destroy', true);
assertLastStatus(players[2], 'destroy', true);
});
assertLastStatus(players[0], 'destroy', false);
assertLastStatus(players[1], 'destroy', false);
assertLastStatus(players[2], 'destroy', false);
});

it('should function without any players', () => {
var sequence = new AnimationSequencePlayer([]);
Expand Down Expand Up @@ -215,5 +196,31 @@ export function main() {
flushMicrotasks();
expect(completed).toEqual(true);
}));

it('should not allow the player to be destroyed if it already has been destroyed unless reset',
fakeAsync(() => {
var p1 = new MockAnimationPlayer();
var p2 = new MockAnimationPlayer();
var innerPlayers = [p1, p2];

var sequencePlayer = new AnimationSequencePlayer(innerPlayers);
expect(p1.log[p1.log.length - 1]).not.toContain('destroy');
expect(p2.log[p2.log.length - 1]).not.toContain('destroy');

sequencePlayer.destroy();
expect(p1.log[p1.log.length - 1]).toContain('destroy');
expect(p2.log[p2.log.length - 1]).toContain('destroy');

p1.log = p2.log = [];

sequencePlayer.destroy();
expect(p1.log[p1.log.length - 1]).not.toContain('destroy');
expect(p2.log[p2.log.length - 1]).not.toContain('destroy');

sequencePlayer.reset();
sequencePlayer.destroy();
expect(p1.log[p1.log.length - 1]).toContain('destroy');
expect(p2.log[p2.log.length - 1]).toContain('destroy');
}));
});
}
13 changes: 7 additions & 6 deletions modules/@angular/core/testing/mock_animation_player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
*/

import {AnimationPlayer} from '@angular/core';
import {isPresent} from './facade/lang';

export class MockAnimationPlayer implements AnimationPlayer {
private _onDoneFns: Function[] = [];
private _onStartFns: Function[] = [];
private _finished = false;
private _destroyed = false;
private _started: boolean = false;
private _started = false;

public parentPlayer: AnimationPlayer = null;

Expand All @@ -27,9 +26,6 @@ export class MockAnimationPlayer implements AnimationPlayer {

this._onDoneFns.forEach(fn => fn());
this._onDoneFns = [];
if (!isPresent(this.parentPlayer)) {
this.destroy();
}
}
}

Expand All @@ -56,7 +52,12 @@ export class MockAnimationPlayer implements AnimationPlayer {

finish(): void { this._onFinish(); }

reset(): void { this.log.push('reset'); }
reset(): void {
this.log.push('reset');
this._destroyed = false;
this._finished = false;
this._started = false;
}

destroy(): void {
if (!this._destroyed) {
Expand Down
Loading