Skip to content

Commit f0110aa

Browse files
committed
refactor(animations): deprecation of AnimationDriver.NOOP
The `NoopAnimationDriver` as static property of `AnimationDriver` prevents it from being removed by tree shaking. This commit deprecates it and exposes the `NoopAnimationDriver` on the public API to replace its usage. DEPRECATED: The `AnimationDriver.NOOP` symbol is deprecated, use `NoopAnimationDriver` instead.
1 parent 0a4f18a commit f0110aa

File tree

7 files changed

+69
-5
lines changed

7 files changed

+69
-5
lines changed

aio/content/guide/deprecations.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ v16 - v19
129129

130130
| Area | API or Feature | Deprecated in | May be removed in |
131131
|:--- |:--- |:--- |:--- |
132+
| `@angular/animations` | `AnimationDriver.NOOP` | v17 | v19 |
132133
| `@angular/core` | `PACKAGE_ROOT_URL` | v17 | v19 |
133134

134135
### Deprecated features with no planned removal version
@@ -150,6 +151,14 @@ In the [API reference section](api) of this site, deprecated APIs are indicated
150151

151152
</div>
152153

154+
<a id="animations"></a>
155+
156+
### &commat;angular/animations
157+
158+
| API | Replacement | Deprecation announced | Details |
159+
|:--- |:--- |:--- |:--- |
160+
| [AnimationDriver.NOOP](api/animations/browser/AnimationDriver#NOOP) | `NoopAnimationDriver` | v17 | Create a new `NoopAnimationDriver` directly instead of calling `AnimationDriver.NOOP`
161+
153162
<a id="common"></a>
154163

155164
### &commat;angular/common

goldens/public-api/animations/browser/index.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
55
```ts
66

7+
import { AnimationPlayer } from '@angular/animations';
8+
import * as i0 from '@angular/core';
9+
710
// @public (undocumented)
811
export abstract class AnimationDriver {
912
// (undocumented)
@@ -15,7 +18,7 @@ export abstract class AnimationDriver {
1518
abstract getParentElement(element: unknown): unknown;
1619
// @deprecated (undocumented)
1720
abstract matchesElement(element: any, selector: string): boolean;
18-
// (undocumented)
21+
// @deprecated (undocumented)
1922
static NOOP: AnimationDriver;
2023
// (undocumented)
2124
abstract query(element: any, selector: string, multi: boolean): any[];
@@ -25,6 +28,28 @@ export abstract class AnimationDriver {
2528
abstract validateStyleProperty(prop: string): boolean;
2629
}
2730

31+
// @public
32+
export class NoopAnimationDriver implements AnimationDriver {
33+
// (undocumented)
34+
animate(element: any, keyframes: Array<Map<string, string | number>>, duration: number, delay: number, easing: string, previousPlayers?: any[], scrubberAccessRequested?: boolean): AnimationPlayer;
35+
// (undocumented)
36+
computeStyle(element: any, prop: string, defaultValue?: string): string;
37+
// (undocumented)
38+
containsElement(elm1: any, elm2: any): boolean;
39+
// (undocumented)
40+
getParentElement(element: unknown): unknown;
41+
// @deprecated (undocumented)
42+
matchesElement(_element: any, _selector: string): boolean;
43+
// (undocumented)
44+
query(element: any, selector: string, multi: boolean): any[];
45+
// (undocumented)
46+
validateStyleProperty(prop: string): boolean;
47+
// (undocumented)
48+
static ɵfac: i0.ɵɵFactoryDeclaration<NoopAnimationDriver, never>;
49+
// (undocumented)
50+
static ɵprov: i0.ɵɵInjectableDeclaration<NoopAnimationDriver>;
51+
}
52+
2853
// (No @packageDocumentation comment for this package)
2954

3055
```

packages/animations/browser/src/browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
* @description
1212
* Entry point for all animation APIs of the animation browser package.
1313
*/
14-
export {AnimationDriver} from './render/animation_driver';
14+
export {AnimationDriver, NoopAnimationDriver} from './render/animation_driver';
1515
export * from './private_export';

packages/animations/browser/src/private_export.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
export {Animation as ɵAnimation} from './dsl/animation';
99
export {AnimationStyleNormalizer as ɵAnimationStyleNormalizer, NoopAnimationStyleNormalizer as ɵNoopAnimationStyleNormalizer} from './dsl/style_normalization/animation_style_normalizer';
1010
export {WebAnimationsStyleNormalizer as ɵWebAnimationsStyleNormalizer} from './dsl/style_normalization/web_animations_style_normalizer';
11-
export {NoopAnimationDriver as ɵNoopAnimationDriver} from './render/animation_driver';
1211
export {AnimationEngine as ɵAnimationEngine} from './render/animation_engine_next';
1312
export {containsElement as ɵcontainsElement, getParentElement as ɵgetParentElement, invokeQuery as ɵinvokeQuery, validateStyleProperty as ɵvalidateStyleProperty, validateWebAnimatableStyleProperty as ɵvalidateWebAnimatableStyleProperty} from './render/shared';
1413
export {WebAnimationsDriver as ɵWebAnimationsDriver} from './render/web_animations/web_animations_driver';

packages/animations/browser/src/render/animation_driver.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,61 @@ import {Injectable} from '@angular/core';
1010

1111
import {containsElement, getParentElement, invokeQuery, validateStyleProperty} from './shared';
1212

13+
/**
14+
* @publicApi
15+
*
16+
* `AnimationDriver` implentation for Noop animations
17+
*/
1318
@Injectable()
1419
export class NoopAnimationDriver implements AnimationDriver {
20+
/**
21+
* @returns Whether `prop` is a valid CSS property
22+
*/
1523
validateStyleProperty(prop: string): boolean {
1624
return validateStyleProperty(prop);
1725
}
1826

27+
/**
28+
* @deprecated unused
29+
*/
1930
matchesElement(_element: any, _selector: string): boolean {
2031
// This method is deprecated and no longer in use so we return false.
2132
return false;
2233
}
2334

35+
/**
36+
*
37+
* @returns Whether elm1 contains elm2.
38+
*/
2439
containsElement(elm1: any, elm2: any): boolean {
2540
return containsElement(elm1, elm2);
2641
}
2742

43+
/**
44+
* @returns Rhe parent of the given element or `null` if the element is the `document`
45+
*/
2846
getParentElement(element: unknown): unknown {
2947
return getParentElement(element);
3048
}
3149

50+
/**
51+
* @returns The result of the query selector on the element. The array will contain up to 1 item
52+
* if `multi` is `false`.
53+
*/
3254
query(element: any, selector: string, multi: boolean): any[] {
3355
return invokeQuery(element, selector, multi);
3456
}
3557

58+
/**
59+
* @returns The `defaultValue` or empty string
60+
*/
3661
computeStyle(element: any, prop: string, defaultValue?: string): string {
3762
return defaultValue || '';
3863
}
3964

65+
/**
66+
* @returns An `NoopAnimationPlayer`
67+
*/
4068
animate(
4169
element: any, keyframes: Array<Map<string, string|number>>, duration: number, delay: number,
4270
easing: string, previousPlayers: any[] = [],
@@ -49,6 +77,9 @@ export class NoopAnimationDriver implements AnimationDriver {
4977
* @publicApi
5078
*/
5179
export abstract class AnimationDriver {
80+
/**
81+
* @deprecated Use the NoopAnimationDriver class.
82+
*/
5283
static NOOP: AnimationDriver = (/* @__PURE__ */ new NoopAnimationDriver());
5384

5485
abstract validateStyleProperty(prop: string): boolean;

packages/core/test/animation/animation_integration_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import {animate, animateChild, animation, AnimationEvent, AnimationMetadata, AnimationOptions, AUTO_STYLE, group, keyframes, query, sequence, state, style, transition, trigger, useAnimation, ɵPRE_STYLE as PRE_STYLE} from '@angular/animations';
9-
import {AnimationDriver, ɵAnimationEngine, ɵNoopAnimationDriver as NoopAnimationDriver} from '@angular/animations/browser';
9+
import {AnimationDriver, NoopAnimationDriver, ɵAnimationEngine} from '@angular/animations/browser';
1010
import {MockAnimationDriver, MockAnimationPlayer} from '@angular/animations/browser/testing';
1111
import {ChangeDetectorRef, Component, HostBinding, HostListener, Inject, RendererFactory2, ViewChild, ViewContainerRef} from '@angular/core';
1212
import {fakeAsync, flushMicrotasks, TestBed} from '@angular/core/testing';

packages/platform-browser/animations/src/providers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {AnimationBuilder} from '@angular/animations';
10-
import {AnimationDriver, ɵAnimationEngine as AnimationEngine, ɵAnimationStyleNormalizer as AnimationStyleNormalizer, ɵNoopAnimationDriver as NoopAnimationDriver, ɵWebAnimationsDriver as WebAnimationsDriver, ɵWebAnimationsStyleNormalizer as WebAnimationsStyleNormalizer} from '@angular/animations/browser';
10+
import {AnimationDriver, NoopAnimationDriver, ɵAnimationEngine as AnimationEngine, ɵAnimationStyleNormalizer as AnimationStyleNormalizer, ɵWebAnimationsDriver as WebAnimationsDriver, ɵWebAnimationsStyleNormalizer as WebAnimationsStyleNormalizer} from '@angular/animations/browser';
1111
import {DOCUMENT} from '@angular/common';
1212
import {ANIMATION_MODULE_TYPE, ApplicationRef, Inject, Injectable, NgZone, OnDestroy, Provider, RendererFactory2} from '@angular/core';
1313
import {ɵDomRendererFactory2 as DomRendererFactory2} from '@angular/platform-browser';

0 commit comments

Comments
 (0)