Scaffold: cache children with memo
This commit is contained in:
parent
b1812392cb
commit
62a80ddce2
1 changed files with 17 additions and 12 deletions
|
@ -2,6 +2,7 @@ import { createElementSize } from "@solid-primitives/resize-observer";
|
||||||
import {
|
import {
|
||||||
JSX,
|
JSX,
|
||||||
Show,
|
Show,
|
||||||
|
children,
|
||||||
createRenderEffect,
|
createRenderEffect,
|
||||||
createSignal,
|
createSignal,
|
||||||
splitProps,
|
splitProps,
|
||||||
|
@ -21,8 +22,8 @@ type ScaffoldProps = ParentProps<
|
||||||
/**
|
/**
|
||||||
* The passthrough props are passed to the content container.
|
* The passthrough props are passed to the content container.
|
||||||
*/
|
*/
|
||||||
const Scaffold: Component<ScaffoldProps> = (props) => {
|
const Scaffold: Component<ScaffoldProps> = (oprops) => {
|
||||||
const [managed, rest] = splitProps(props, [
|
const [props, rest] = splitProps(oprops, [
|
||||||
"topbar",
|
"topbar",
|
||||||
"fab",
|
"fab",
|
||||||
"bottom",
|
"bottom",
|
||||||
|
@ -34,9 +35,13 @@ const Scaffold: Component<ScaffoldProps> = (props) => {
|
||||||
|
|
||||||
const topbarSize = createElementSize(topbarElement);
|
const topbarSize = createElementSize(topbarElement);
|
||||||
|
|
||||||
|
const topbar = children(() => props.topbar)
|
||||||
|
const fab = children(() => props.fab)
|
||||||
|
const bottom = children(() => props.bottom)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class={`Scaffold ${managed.class || ""}`}
|
class={`Scaffold ${props.class || ""}`}
|
||||||
ref={(e) => {
|
ref={(e) => {
|
||||||
createRenderEffect(() => {
|
createRenderEffect(() => {
|
||||||
e.style.setProperty(
|
e.style.setProperty(
|
||||||
|
@ -45,28 +50,28 @@ const Scaffold: Component<ScaffoldProps> = (props) => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (managed.ref) {
|
if (props.ref) {
|
||||||
(managed.ref as (val: typeof e) => void)(e);
|
(props.ref as (val: typeof e) => void)(e);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
{...rest}
|
{...rest}
|
||||||
>
|
>
|
||||||
<Show when={props.topbar}>
|
<Show when={topbar()}>
|
||||||
<div class="topbar" ref={setTopbarElement} role="presentation">
|
<div class="topbar" ref={setTopbarElement} role="presentation">
|
||||||
{props.topbar}
|
{topbar()}
|
||||||
</div>
|
</div>
|
||||||
</Show>
|
</Show>
|
||||||
<Show when={props.fab}>
|
<Show when={fab()}>
|
||||||
<div class="fab-dock" role="presentation">
|
<div class="fab-dock" role="presentation">
|
||||||
{props.fab}
|
{fab()}
|
||||||
</div>
|
</div>
|
||||||
</Show>
|
</Show>
|
||||||
|
|
||||||
{managed.children}
|
{props.children}
|
||||||
|
|
||||||
<Show when={props.bottom}>
|
<Show when={bottom()}>
|
||||||
<div class="bottom-dock" role="presentation">
|
<div class="bottom-dock" role="presentation">
|
||||||
{props.bottom}
|
{bottom()}
|
||||||
</div>
|
</div>
|
||||||
</Show>
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue