diff options
author | Sebastian <sebasjm@gmail.com> | 2024-02-27 01:18:23 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-02-27 01:18:23 -0300 |
commit | ee40a5e25c44ef478ee13426549e548d2610a215 (patch) | |
tree | 05978a180aaa2d334ef65b829d611cdd383fda37 /packages/web-util/src | |
parent | de8468fcd7f1c74b820486fb6d8854c758458780 (diff) | |
download | wallet-core-ee40a5e25c44ef478ee13426549e548d2610a215.tar.xz |
conversion UI
Diffstat (limited to 'packages/web-util/src')
-rw-r--r-- | packages/web-util/src/components/utils.ts | 28 |
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 |