diff --git a/src/hooks.ts b/src/hooks.ts index adc1cd50..dc9a3d47 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -35,25 +35,33 @@ export function useState(state: T): T { // Life cycle hooks // ----------------------------------------------------------------------------- function makeLifecycleHook(method: string, reverse: boolean = false) { - return function(cb) { - const component: Component = Component._current; - if (component.__owl__[method]) { - const current = component.__owl__[method]; - if (reverse) { + if (reverse) { + return function(cb) { + const component: Component = 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 = 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);