Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit e88d178

Browse files
committed
Reset timeout onUnmount
1 parent effbe86 commit e88d178

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

‎src/composables/withTimeout.spec.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,24 @@ describe("withTimeout", () => {
9797
}, halfPeriod);
9898
}, halfPeriod);
9999
});
100+
101+
it("should not call timeout after unmount", (done) => {
102+
const props = {
103+
transitionState: {
104+
inTransition: false,
105+
},
106+
transitionInfo: {
107+
totalDuration: 20,
108+
},
109+
timeout: spy(),
110+
};
111+
const timeoutIn = props.transitionInfo.totalDuration * timeoutMultiplier;
112+
const wrapper = mount(<Assembly {...props} />);
113+
wrapper.setProps({ transitionState: { inTransition: true } });
114+
wrapper.unmount();
115+
setTimeout(() => {
116+
assert.isFalse(props.timeout.called);
117+
done();
118+
}, timeoutIn);
119+
});
100120
});

‎src/composables/withTimeout.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { withHandlers, isolate, onWillReceiveProps, debug } from "reassemble";
1+
import { withHandlers, isolate, onWillReceiveProps, onWillUnmount } from "reassemble";
22

33
import { CSSTransitionProps } from "../csstransition";
44
import { WithTransitionStateProps } from "./withTransitionState";
@@ -45,4 +45,5 @@ export const withTimeout =
4545
}
4646
}
4747
}),
48+
onWillUnmount<PropsUnion>(({ cancel }) => cancel()),
4849
);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /