Skip to content

Commit

Permalink
Add stack.index and stack.size to call properties
Browse files Browse the repository at this point in the history
  • Loading branch information
desko27 committed Sep 11, 2024
1 parent 8b2aaee commit 48f26ae
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bundlesize.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"files": [
{
"path": "./dist/*.js",
"maxSize": "550 B"
"maxSize": "555 B"
}
]
}
8 changes: 6 additions & 2 deletions lib/createCallable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ export function createCallable<Props = void, Response = void, RootProps = {}>(
}
}, [])

return stack.map(({ props, ...call }) => (
return stack.map(({ props, ...call }, index) => (
<UserComponent
{...props}
key={call.key}
call={{ ...call, root: rootProps, stackSize: stack.length }}
call={{
...call,
root: rootProps,
stack: { index, size: stack.length },
}}
/>
))
},
Expand Down
2 changes: 1 addition & 1 deletion lib/createCallable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type CallFunction<Props, Response> = (props: Props) => Promise<Response>
export type CallContext<Props, Response, RootProps> = Omit<
PrivateCallContext<Props, Response>,
'props'
> & { root: RootProps; stackSize: number }
> & { root: RootProps; stack: { index: number; size: number } }

/**
* User props + the call prop
Expand Down
2 changes: 1 addition & 1 deletion src/CallableScenes/YourNested.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const YourNested = createCallable<
if (!isMounted) onCallNested(i)
}, [])

if (i < call.stackSize - DOM_LIMIT_TO_VIRTUALIZE) return null
if (call.stack.index < call.stack.size - DOM_LIMIT_TO_VIRTUALIZE) return null

return (
<Dialog color="pink" ended={call.ended}>
Expand Down

0 comments on commit 48f26ae

Please sign in to comment.