Skip to content

Commit

Permalink
refactor(animations): remove unecessary interface (angular#50662)
Browse files Browse the repository at this point in the history
`Animation` is provided by `lib.dom`.

PR Close angular#50662
  • Loading branch information
JeanMeche authored and dylhunn committed Aug 7, 2023
1 parent 6a7c1ab commit 10bab47
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 40 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {AnimationPlayer, ɵStyleDataMap} from '@angular/animations';
import {computeStyle} from '../../util';
import {SpecialCasedStyles} from '../special_cased_styles';

import {DOMAnimation} from './dom_animation';

export class WebAnimationsPlayer implements AnimationPlayer {
private _onDoneFns: Function[] = [];
private _onStartFns: Function[] = [];
Expand All @@ -31,7 +29,7 @@ export class WebAnimationsPlayer implements AnimationPlayer {
private _originalOnStartFns: Function[] = [];

// using non-null assertion because it's re(set) by init();
public readonly domPlayer!: DOMAnimation;
public readonly domPlayer!: Animation;
public time = 0;

public parentPlayer: AnimationPlayer|null = null;
Expand Down Expand Up @@ -88,10 +86,9 @@ export class WebAnimationsPlayer implements AnimationPlayer {
}

/** @internal */
_triggerWebAnimation(element: any, keyframes: Array<ɵStyleDataMap>, options: any): DOMAnimation {
// jscompiler doesn't seem to know animate is a native property because it's not fully
// supported yet across common browsers (we polyfill it for Edge/Safari) [CL #143630929]
return element['animate'](this._convertKeyframesToObject(keyframes), options) as DOMAnimation;
_triggerWebAnimation(element: HTMLElement, keyframes: Array<ɵStyleDataMap>, options: any):
Animation {
return element.animate(this._convertKeyframesToObject(keyframes), options);
}

onStart(fn: () => void): void {
Expand Down Expand Up @@ -180,7 +177,8 @@ export class WebAnimationsPlayer implements AnimationPlayer {
}

getPosition(): number {
return this.domPlayer.currentTime / this.time;
// tsc is complaining with TS2362 without the conversion to number
return +(this.domPlayer.currentTime ?? 0) / this.time;
}

get totalTime(): number {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {DOMAnimation} from '../../../src/render/web_animations/dom_animation';
import {WebAnimationsPlayer} from '../../../src/render/web_animations/web_animations_player';

{
Expand Down Expand Up @@ -91,7 +90,7 @@ import {WebAnimationsPlayer} from '../../../src/render/web_animations/web_animat
});
}

class MockDomAnimation implements DOMAnimation {
class MockDomAnimation implements Animation {
log: string[] = [];
cancel(): void {
this.log.push('cancel');
Expand All @@ -105,9 +104,53 @@ class MockDomAnimation implements DOMAnimation {
finish(): void {
this.log.push('finish');
}
onfinish: Function = () => {};
position: number = 0;
currentTime: number = 0;

// Other properties to ensure conformnce to interface
effect: AnimationEffect|null = null;
finished: Promise<Animation> = Promise.resolve({} as any);
id: string = '';
oncancel: ((this: Animation, ev: AnimationPlaybackEvent) => any)|null = null;
onfinish: ((this: Animation, ev: AnimationPlaybackEvent) => any)|null = null;
onremove: ((this: Animation, ev: Event) => any)|null = null;
pending: boolean = false;
playState: AnimationPlayState = 'running';
playbackRate: number = 0;
ready: Promise<Animation> = Promise.resolve({} as any);
replaceState: AnimationReplaceState = 'active';
startTime: number|null = null;
timeline: AnimationTimeline|null = null;
commitStyles(): void {
throw new Error('Method not implemented.');
}
persist(): void {
throw new Error('Method not implemented.');
}
reverse(): void {
throw new Error('Method not implemented.');
}
updatePlaybackRate(playbackRate: number): void {
throw new Error('Method not implemented.');
}
removeEventListener<K extends keyof AnimationEventMap>(
type: K, listener: (this: Animation, ev: AnimationEventMap[K]) => any,
options?: boolean|EventListenerOptions|undefined): void;
removeEventListener(
type: string, listener: EventListenerOrEventListenerObject,
options?: boolean|EventListenerOptions|undefined): void;
removeEventListener(type: unknown, listener: unknown, options?: unknown): void {
throw new Error('Method not implemented.');
}
dispatchEvent(event: Event): boolean;
dispatchEvent(event: Event): boolean;
dispatchEvent(event: unknown): boolean {
throw new Error('Method not implemented.');
}
removeAllListeners?(eventName?: string|undefined): void {
throw new Error('Method not implemented.');
}
eventListeners?(eventName?: string|undefined): EventListenerOrEventListenerObject[] {
throw new Error('Method not implemented.');
}
addEventListener(eventName: string, handler: (event: any) => any): any {}
dispatchEvent(eventName: string): any {}
}

0 comments on commit 10bab47

Please sign in to comment.