Remove timeouts from call unsubs (#2393)

This commit is contained in:
Jaco Greeff 2020-03-16 10:50:53 +01:00 committed by GitHub
parent fd533227b6
commit 78bef6d4c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -59,9 +59,7 @@ function unsubscribe (tracker: TrackerRef): void {
tracker.current.isActive = false;
if (tracker.current.subscriber) {
tracker.current.subscriber.then((unsubFn): void => {
setTimeout(unsubFn, 0);
});
tracker.current.subscriber.then((unsubFn): void => unsubFn());
tracker.current.subscriber = null;
}
}
@ -87,11 +85,11 @@ function subscribe <T> (mounted: MountedRef, tracker: TrackerRef, fn: TrackFn |
if (mounted.current && tracker.current.isActive && (!isSingle || !tracker.current.count)) {
tracker.current.count++;
((transformed: any): void => {
setTimeout((): void => {
mounted.current && tracker.current.isActive && setValue(transformed);
}, 0);
})(withParams ? [params, transform(value)] : transform(value));
mounted.current && tracker.current.isActive && setValue(
withParams
? [params, transform(value)] as any
: transform(value)
);
}
});
} else {
@ -112,9 +110,7 @@ export default function useCall <T> (fn: TrackFn | undefined | null | false, par
// initial effect, we need an un-subscription
useEffect((): () => void => {
return (): void => {
setTimeout(() => unsubscribe(tracker), 0);
};
return (): void => unsubscribe(tracker);
}, []);
// on changes, re-subscribe