[IMP] component: re-introduce error handling in lifecycle

This commit is contained in:
Lucas Perais (lpe)
2021-11-08 10:30:36 +01:00
committed by Aaron Bohy
parent bca6afeb90
commit e0c0306acd
8 changed files with 668 additions and 65 deletions
+13
View File
@@ -1,4 +1,5 @@
import { getCurrent } from "./component_node";
import { nodeErrorHandlers } from "./error_handling";
// -----------------------------------------------------------------------------
// hooks
@@ -47,3 +48,15 @@ export function onRender(fn: () => void | any) {
return renderFn();
};
}
export function onError(fn: (error: Error) => void | any) {
const node = getCurrent()!;
let handlers = nodeErrorHandlers.get(node);
if (handlers) {
handlers.push(fn);
} else {
handlers = [];
handlers.push(fn);
nodeErrorHandlers.set(node, handlers);
}
}