mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP[ component/hooks: add onWillStart and onWillUpdateProps
This commit is contained in:
+18
-2
@@ -64,11 +64,28 @@ function makeLifecycleHook(method: string, reverse: boolean = false) {
|
||||
}
|
||||
}
|
||||
|
||||
function makeAsyncHook(method: string) {
|
||||
return function(cb) {
|
||||
const component: Component<any, any> = Component._current;
|
||||
if (component.__owl__[method]) {
|
||||
const current = component.__owl__[method];
|
||||
component.__owl__[method] = function(...args) {
|
||||
return Promise.all[(current.call(component, ...args), cb.call(component, ...args))];
|
||||
};
|
||||
} else {
|
||||
component.__owl__[method] = cb;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const onMounted = makeLifecycleHook("mountedCB", true);
|
||||
export const onWillUnmount = makeLifecycleHook("willUnmountCB");
|
||||
export const onWillPatch = makeLifecycleHook("willPatchCB");
|
||||
export const onPatched = makeLifecycleHook("patchedCB", true);
|
||||
|
||||
export const onWillStart = makeAsyncHook("willStartCB");
|
||||
export const onWillUpdateProps = makeAsyncHook("willUpdatePropsCB");
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// useRef
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -100,7 +117,6 @@ export function useRef(name: string): Ref {
|
||||
// useSubEnv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* This hook is a simple way to let components use a sub environment. Note that
|
||||
* like for all hooks, it is important that this is only called in the
|
||||
@@ -109,4 +125,4 @@ export function useRef(name: string): Ref {
|
||||
export function useSubEnv(nextEnv) {
|
||||
const component = Component._current;
|
||||
component.env = Object.assign(Object.create(component.env), nextEnv);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user