Skip to content

Commit fdf1beb

Browse files
committed
Refactor
1 parent 06032cc commit fdf1beb

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/hooks/useAnimation.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ export const useAnimation = (
7575
const getAnimation = () => cache?.[0];
7676
const handle = createHandle();
7777

78+
const cancel = () => {
79+
handle._cancel(getAnimation());
80+
};
81+
7882
const externalHandle: AnimationHandle = {
7983
play: (opts) => {
8084
handle._play(initAnimation(getKeyframes(), getOptions()), opts);
@@ -85,7 +89,7 @@ export const useAnimation = (
8589
return externalHandle;
8690
},
8791
cancel: () => {
88-
handle._cancel(getAnimation());
92+
cancel();
8993
return externalHandle;
9094
},
9195
finish: () => {
@@ -114,7 +118,7 @@ export const useAnimation = (
114118
return [
115119
externalHandle,
116120
() => {
117-
handle._cancel(getAnimation());
121+
cancel();
118122
},
119123
];
120124
})[0];

src/hooks/useAnimationController.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ export const useAnimationController = <ID extends string>(
3838
);
3939
};
4040

41+
const cancelAll = () => {
42+
forAllHandle((handle) => {
43+
handle.cancel();
44+
});
45+
};
46+
4147
const externalHandle: AnimationController<ID> = {
4248
get: getHandle,
4349
playAll: (opts) => {
@@ -53,9 +59,7 @@ export const useAnimationController = <ID extends string>(
5359
return externalHandle;
5460
},
5561
cancelAll: () => {
56-
forAllHandle((handle) => {
57-
handle.cancel();
58-
});
62+
cancelAll();
5963
return externalHandle;
6064
},
6165
finishAll: () => {
@@ -79,7 +83,7 @@ export const useAnimationController = <ID extends string>(
7983
return [
8084
externalHandle,
8185
() => {
82-
externalHandle.cancelAll();
86+
cancelAll();
8387
},
8488
];
8589
}

src/hooks/useAnimationFunction.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ export const useAnimationFunction = (
7979
const getAnimation = () => cache?.[0];
8080
const handle = createHandle();
8181

82+
const cancel = () => {
83+
handle._cancel(getAnimation());
84+
};
85+
8286
const externalHandle: AnimationFunctionHandle = {
8387
play: (opts) => {
8488
handle._play(initAnimation(getOptions()), opts);
@@ -89,7 +93,7 @@ export const useAnimationFunction = (
8993
return externalHandle;
9094
},
9195
cancel: () => {
92-
handle._cancel(getAnimation());
96+
cancel();
9397
return externalHandle;
9498
},
9599
finish: () => {
@@ -113,7 +117,7 @@ export const useAnimationFunction = (
113117
return [
114118
externalHandle,
115119
() => {
116-
handle._cancel(getAnimation());
120+
cancel();
117121
},
118122
];
119123
}

0 commit comments

Comments
 (0)