Skip to content

Commit

Permalink
Rollback deferred to old version
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia committed Jul 25, 2024
1 parent 9e38075 commit e24dfd5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"std/": "https://deno.land/[email protected]/",
"partytown/": "https://deno.land/x/[email protected]/",
"deco-sites/std/": "https://denopkg.com/deco-sites/[email protected]/",
"deco/": "https://cdn.jsdelivr.net/gh/deco-cx/deco@30aa5339af59f53d5452b29eebde196a1df66a16/"
"deco/": "https://cdn.jsdelivr.net/gh/deco-cx/deco@1.80.0/"
},
"lock": false,
"tasks": {
Expand Down
31 changes: 16 additions & 15 deletions htmx/sections/Deferred.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import type { Section } from "deco/blocks/section.ts";
import { useSection } from "deco/hooks/useSection.ts";
import { asResolved, isDeferred } from "deco/mod.ts";
import { renderSection, shouldForceRender } from "../../utils/deferred.tsx";
import { AppContext } from "../mod.ts";
import { shouldForceRender } from "../../utils/deferred.ts";

/**
* @titleBy type
* @description fires once when the element is first loaded
*/
interface Load {
type: "load";

// TODO: @gimenes add delay
/** @hide true */
delay?: number;
}

Expand All @@ -35,18 +34,19 @@ interface Intersect {

export interface Props {
sections: Section[];
fallback?: Section;
/** @hide true */
fallbacks?: Section[];
trigger?: Load | Revealed | Intersect;
loading?: "lazy" | "eager";
}

const Deferred = (props: Props) => {
const { sections, loading, trigger, fallback } = props;
const { sections, loading, trigger } = props;

if (loading === "eager") {
return (
<>
{sections.map(({ Component, props }) => <Component {...props} />)}
{sections.map(renderSection)}
</>
);
}
Expand All @@ -61,15 +61,16 @@ const Deferred = (props: Props) => {
}

return (
<div
hx-get={href}
hx-trigger={`${trigger?.type ?? "load"} once`}
hx-target="closest section"
hx-swap="outerHTML"
style={{ height: "100vh" }}
>
{fallback && <fallback.Component {...fallback.props} />}
</div>
<>
<div
hx-get={href}
hx-trigger={triggerList.join(" ")}
hx-target="closest section"
hx-swap="outerHTML"
style={{ height: "100vh" }}
/>
{props.fallbacks?.map(renderSection)}
</>
);
};

Expand Down

0 comments on commit e24dfd5

Please sign in to comment.