mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REF] hooks: improve makeLifecycleHook
This commit is contained in:
+17
-9
@@ -35,25 +35,33 @@ export function useState<T>(state: T): T {
|
|||||||
// Life cycle hooks
|
// Life cycle hooks
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
function makeLifecycleHook(method: string, reverse: boolean = false) {
|
function makeLifecycleHook(method: string, reverse: boolean = false) {
|
||||||
return function(cb) {
|
if (reverse) {
|
||||||
const component: Component<any, any> = Component._current;
|
return function(cb) {
|
||||||
if (component.__owl__[method]) {
|
const component: Component<any, any> = Component._current;
|
||||||
const current = component.__owl__[method];
|
if (component.__owl__[method]) {
|
||||||
if (reverse) {
|
const current = component.__owl__[method];
|
||||||
component.__owl__[method] = function() {
|
component.__owl__[method] = function() {
|
||||||
current.call(component);
|
current.call(component);
|
||||||
cb.call(component);
|
cb.call(component);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
component.__owl__[method] = cb;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return function(cb) {
|
||||||
|
const component: Component<any, any> = Component._current;
|
||||||
|
if (component.__owl__[method]) {
|
||||||
|
const current = component.__owl__[method];
|
||||||
component.__owl__[method] = function() {
|
component.__owl__[method] = function() {
|
||||||
cb.call(component);
|
cb.call(component);
|
||||||
current.call(component);
|
current.call(component);
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
component.__owl__[method] = cb;
|
||||||
}
|
}
|
||||||
} else {
|
};
|
||||||
component.__owl__[method] = cb;
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const onMounted = makeLifecycleHook("mountedCB", true);
|
export const onMounted = makeLifecycleHook("mountedCB", true);
|
||||||
|
|||||||
Reference in New Issue
Block a user