[MOV] move lifecycle_hooks into component/

This commit is contained in:
Géry Debongnie
2021-10-19 09:26:18 +02:00
committed by Aaron Bohy
parent d7f3f4defe
commit 8c71d99e5f
4 changed files with 4 additions and 4 deletions
+49
View File
@@ -0,0 +1,49 @@
import { getCurrent } from "./component_node";
// -----------------------------------------------------------------------------
// hooks
// -----------------------------------------------------------------------------
export function onWillStart(fn: () => Promise<void> | void | any) {
const node = getCurrent()!;
node.willStart.push(fn);
}
export function onWillUpdateProps(fn: (nextProps: any) => Promise<void> | void | any) {
const node = getCurrent()!;
node.willUpdateProps.push(fn);
}
export function onMounted(fn: () => void | any) {
const node = getCurrent()!;
node.mounted.push(fn);
}
export function onWillPatch(fn: () => Promise<void> | any | void) {
const node = getCurrent()!;
node.willPatch.push(fn);
}
export function onPatched(fn: () => void | any) {
const node = getCurrent()!;
node.patched.push(fn);
}
export function onWillUnmount(fn: () => Promise<void> | void | any) {
const node = getCurrent()!;
node.willUnmount.push(fn);
}
export function onDestroyed(fn: () => Promise<void> | void | any) {
const node = getCurrent()!;
node.destroyed.push(fn);
}
export function onRender(fn: () => void | any) {
const node = getCurrent()!;
const renderFn = node.renderFn;
node.renderFn = () => {
fn();
return renderFn();
};
}