mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] useEffect: can depend on dom dependencies
Because the dependencies are now computed in patched.
This commit is contained in:
committed by
Aaron Bohy
parent
3c98ef8cb1
commit
bd5637c0a3
+6
-11
@@ -1,6 +1,6 @@
|
||||
import type { Env } from "./app/app";
|
||||
import { getCurrent } from "./component/component_node";
|
||||
import { onMounted, onPatched, onWillPatch, onWillUnmount } from "./component/lifecycle_hooks";
|
||||
import { onMounted, onPatched, onWillUnmount } from "./component/lifecycle_hooks";
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// useRef
|
||||
@@ -75,17 +75,12 @@ export function useEffect(effect: Effect, computeDependencies: () => any[] = ()
|
||||
cleanup = effect(...dependencies) || NO_OP;
|
||||
});
|
||||
|
||||
let shouldReapplyOnPatch = false;
|
||||
onWillPatch(() => {
|
||||
const newDeps = computeDependencies();
|
||||
shouldReapplyOnPatch = newDeps.some((val, i) => val !== dependencies[i]);
|
||||
if (shouldReapplyOnPatch) {
|
||||
cleanup();
|
||||
dependencies = newDeps;
|
||||
}
|
||||
});
|
||||
onPatched(() => {
|
||||
if (shouldReapplyOnPatch) {
|
||||
const newDeps = computeDependencies();
|
||||
const shouldReapply = newDeps.some((val, i) => val !== dependencies[i]);
|
||||
if (shouldReapply) {
|
||||
dependencies = newDeps;
|
||||
cleanup();
|
||||
cleanup = effect(...dependencies) || NO_OP;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user