Skip to content

Commit

Permalink
perf(animations): use ngDevMode to tree-shake warning (#39964)
Browse files Browse the repository at this point in the history
This commit adds ngDevMode guard to show warning only
in dev mode (similar to how things work in other parts of Ivy runtime code).
The ngDevMode flag helps to tree-shake this warning from production builds
(in dev mode everything will work as it works right now) to decrease production bundle size.

PR Close #39964
  • Loading branch information
arturovt authored and mhevery committed Dec 5, 2020
1 parent bf3de9b commit 72aad32
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const TAB_SPACE = ' ';
export class CssKeyframesDriver implements AnimationDriver {
private _count = 0;
private readonly _head: any = document.querySelector('head');
private _warningIssued = false;

validateStyleProperty(prop: string): boolean {
return validateStyleProperty(prop);
Expand Down Expand Up @@ -79,8 +78,8 @@ export class CssKeyframesDriver implements AnimationDriver {
animate(
element: any, keyframes: ɵStyleData[], duration: number, delay: number, easing: string,
previousPlayers: AnimationPlayer[] = [], scrubberAccessRequested?: boolean): AnimationPlayer {
if (scrubberAccessRequested) {
this._notifyFaultyScrubber();
if ((typeof ngDevMode === 'undefined' || ngDevMode) && scrubberAccessRequested) {
notifyFaultyScrubber();
}

const previousCssKeyframePlayers = <CssKeyframesPlayer[]>previousPlayers.filter(
Expand Down Expand Up @@ -117,15 +116,6 @@ export class CssKeyframesDriver implements AnimationDriver {
player.onDestroy(() => removeElement(kfElm));
return player;
}

private _notifyFaultyScrubber() {
if (!this._warningIssued) {
console.warn(
'@angular/animations: please load the web-animations.js polyfill to allow programmatic access...\n',
' visit https://bit.ly/IWukam to learn more about using the web-animation-js polyfill.');
this._warningIssued = true;
}
}
}

function flattenKeyframesIntoStyles(keyframes: null|{[key: string]: any}|
Expand All @@ -146,3 +136,12 @@ function flattenKeyframesIntoStyles(keyframes: null|{[key: string]: any}|
function removeElement(node: any) {
node.parentNode.removeChild(node);
}

let warningIssued = false;
function notifyFaultyScrubber(): void {
if (warningIssued) return;
console.warn(
'@angular/animations: please load the web-animations.js polyfill to allow programmatic access...\n',
' visit https://bit.ly/IWukam to learn more about using the web-animation-js polyfill.');
warningIssued = true;
}

0 comments on commit 72aad32

Please # to comment.