[REF] hooks: improve makeLifecycleHook

This commit is contained in:
Aaron Bohy
2019-10-08 11:12:02 +02:00
committed by aab-odoo
parent cedb1f411f
commit 17ce73e6a9
+17 -9
View File
@@ -35,25 +35,33 @@ export function useState<T>(state: T): T {
// Life cycle hooks
// -----------------------------------------------------------------------------
function makeLifecycleHook(method: string, reverse: boolean = false) {
return function(cb) {
const component: Component<any, any> = Component._current;
if (component.__owl__[method]) {
const current = component.__owl__[method];
if (reverse) {
if (reverse) {
return function(cb) {
const component: Component<any, any> = Component._current;
if (component.__owl__[method]) {
const current = component.__owl__[method];
component.__owl__[method] = function() {
current.call(component);
cb.call(component);
};
} 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() {
cb.call(component);
current.call(component);
};
} else {
component.__owl__[method] = cb;
}
} else {
component.__owl__[method] = cb;
}
};
};
}
}
export const onMounted = makeLifecycleHook("mountedCB", true);