Skip to content

Commit 2e96e7b

Browse files
committed
Remove eager animation from switch directive
1 parent aa6b0ea commit 2e96e7b

File tree

2 files changed

+40
-27
lines changed

2 files changed

+40
-27
lines changed

src/directive/switch/switch.js

+29-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import { getBlockNodes } from "../../shared/jqlite/jqlite";
1+
import { getBlockNodes } from "../../shared/jqlite/jqlite.js";
2+
import { hasAnimate } from "../../shared/utils.js";
3+
import { domInsert } from "../../animations/animate.js";
24

3-
export const ngSwitchDirective = [
4-
"$animate",
5-
($animate) => ({
5+
ngSwitchDirective.$inject = ["$animate"];
6+
7+
/**
8+
* @returns {import('../../types.js').Directive}
9+
*/
10+
export function ngSwitchDirective($animate) {
11+
return {
612
require: "ngSwitch",
713

814
// asks for $scope to fool the BC controller module
@@ -39,18 +45,23 @@ export const ngSwitchDirective = [
3945
for (i = 0, ii = selectedScopes.length; i < ii; ++i) {
4046
const selected = getBlockNodes(selectedElements[i].clone);
4147
selectedScopes[i].$destroy();
42-
const runner = (previousLeaveAnimations[i] =
43-
$animate.leave(selected));
44-
runner.done(spliceFactory(previousLeaveAnimations, i));
48+
49+
if (hasAnimate(selected[0])) {
50+
const runner = (previousLeaveAnimations[i] =
51+
$animate.leave(selected));
52+
runner.done(spliceFactory(previousLeaveAnimations, i));
53+
} else {
54+
selected.remove();
55+
}
4556
}
4657

4758
selectedElements.length = 0;
4859
selectedScopes.length = 0;
4960

5061
if (
5162
(selectedTranscludes =
52-
ngSwitchController.cases[`!${value}`] ||
53-
ngSwitchController.cases["?"])
63+
ngSwitchController['cases'][`!${value}`] ||
64+
ngSwitchController['cases']["?"])
5465
) {
5566
Object.values(selectedTranscludes).forEach((selectedTransclude) => {
5667
selectedTransclude.transclude((caseElement, selectedScope) => {
@@ -60,17 +71,21 @@ export const ngSwitchDirective = [
6071
caseElement[caseElement.length++] = document.createComment("");
6172
const block = { clone: caseElement };
6273
selectedElements.push(block);
63-
$animate.enter(caseElement, anchor.parent(), anchor);
74+
if (hasAnimate(caseElement[0])) {
75+
$animate.enter(caseElement, anchor.parent(), anchor);
76+
} else {
77+
domInsert(caseElement, anchor.parent(), anchor);
78+
}
6479
});
6580
});
6681
}
6782
});
6883
},
69-
}),
70-
];
84+
};
85+
}
7186

7287
/**
73-
* @returns {import('../../types').Directive}
88+
* @returns {import('../../types.js').Directive}
7489
*/
7590
export function ngSwitchWhenDirective() {
7691
return {
@@ -100,7 +115,7 @@ export function ngSwitchWhenDirective() {
100115
}
101116

102117
/**
103-
* @returns {import('../../types').Directive}
118+
* @returns {import('../../types.js').Directive}
104119
*/
105120
export function ngSwitchDefaultDirective() {
106121
return {

types/directive/switch/switch.d.ts

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
/**
2-
* @returns {import('../../types').Directive}
2+
* @returns {import('../../types.js').Directive}
33
*/
4-
export function ngSwitchWhenDirective(): import("../../types").Directive;
4+
export function ngSwitchDirective($animate: any): import("../../types.js").Directive;
5+
export namespace ngSwitchDirective {
6+
let $inject: string[];
7+
}
58
/**
6-
* @returns {import('../../types').Directive}
9+
* @returns {import('../../types.js').Directive}
710
*/
8-
export function ngSwitchDefaultDirective(): import("../../types").Directive;
9-
export const ngSwitchDirective: (string | (($animate: any) => {
10-
require: string;
11-
controller: (string | {
12-
new (): {
13-
cases: {};
14-
};
15-
})[];
16-
link(scope: any, _element: any, attr: any, ngSwitchController: any): void;
17-
}))[];
11+
export function ngSwitchWhenDirective(): import("../../types.js").Directive;
12+
/**
13+
* @returns {import('../../types.js').Directive}
14+
*/
15+
export function ngSwitchDefaultDirective(): import("../../types.js").Directive;

0 commit comments

Comments
 (0)