aboutsummaryrefslogtreecommitdiff
path: root/packages/web-util/src/components/utils.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-02-27 01:18:23 -0300
committerSebastian <sebasjm@gmail.com>2024-02-27 01:18:23 -0300
commitee40a5e25c44ef478ee13426549e548d2610a215 (patch)
tree05978a180aaa2d334ef65b829d611cdd383fda37 /packages/web-util/src/components/utils.ts
parentde8468fcd7f1c74b820486fb6d8854c758458780 (diff)
downloadwallet-core-ee40a5e25c44ef478ee13426549e548d2610a215.tar.gz
wallet-core-ee40a5e25c44ef478ee13426549e548d2610a215.tar.bz2
wallet-core-ee40a5e25c44ef478ee13426549e548d2610a215.zip
conversion UI
Diffstat (limited to 'packages/web-util/src/components/utils.ts')
-rw-r--r--packages/web-util/src/components/utils.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/packages/web-util/src/components/utils.ts b/packages/web-util/src/components/utils.ts
index 34693f7d7..75c3fc0fe 100644
--- a/packages/web-util/src/components/utils.ts
+++ b/packages/web-util/src/components/utils.ts
@@ -12,6 +12,7 @@ export function compose<SType extends { status: string }, PType>(
hook: (p: PType) => RecursiveState<SType>,
viewMap: StateViewMap<SType>,
): (p: PType) => VNode {
+
function withHook(stateHook: () => RecursiveState<SType>): () => VNode {
function ComposedComponent(): VNode {
const state = stateHook();
@@ -35,6 +36,33 @@ export function compose<SType extends { status: string }, PType>(
};
}
+export function recursive<PType>(
+ hook: (p: PType) => RecursiveState<VNode>,
+): (p: PType) => VNode {
+
+ function withHook(stateHook: () => RecursiveState<VNode>): () => VNode {
+ function ComposedComponent(): VNode {
+ const state = stateHook();
+
+ if (typeof state === "function") {
+ const subComponent = withHook(state);
+ return createElement(subComponent, {});
+ }
+
+ return state;
+ }
+
+ return ComposedComponent;
+ }
+
+ return (p: PType) => {
+ const h = withHook(() => hook(p));
+ return h();
+ };
+}
+
+
+
/**
*
* @param obj VNode