Skip to content

Commit

Permalink
fix: preserve user-set onStop callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
hlysine committed May 23, 2023
1 parent 3eee2f7 commit 3c898f3
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,10 @@ export const effect = (
cleanupFn?.();
cleanupFn = fn() ?? undefined;
}, options);
const baseStop = runner.effect.onStop;
runner.effect.onStop = () => {
cleanupFn?.();
baseStop?.();
};
return runner;
};
Expand Down Expand Up @@ -484,8 +486,10 @@ export const watch: WatchOverloads = <
oldValue = effect();
}

const baseStop = effect.effect.onStop;
effect.effect.onStop = () => {
cleanup?.();
baseStop?.();
};

return () => effect.effect.stop();
Expand Down

0 comments on commit 3c898f3

Please sign in to comment.