Skip to content

Commit

Permalink
Return getters from the "For" and "Show" components directly instead …
Browse files Browse the repository at this point in the history
…of creating excessive element objects.
  • Loading branch information
Kapelianovych committed Apr 25, 2024
1 parent beeb6be commit 64e3236
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions packages/moru/components.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { memo } from "./enhancers.js";
import { immediately } from "./context.js";
import { createElement } from "./element.js";

export const For = (
{ each, children, fallback, key = (item) => item },
Expand Down Expand Up @@ -76,7 +75,7 @@ export const For = (
immediately,
);

const List = memo(
return memo(
context,
() => {
const items = elements();
Expand All @@ -85,22 +84,18 @@ export const For = (
},
[elements],
);

return createElement(List, {});
};

export const Show = ({ when, fallback, children }, context) => {
let renderedChildren;
let renderedFallback;

const Conditional = memo(
return memo(
context,
() =>
when()
? (renderedChildren ??= context.resolve(children))
: (renderedFallback ??= context.resolve(fallback)),
[when],
);

return createElement(Conditional, {});
};

0 comments on commit 64e3236

Please sign in to comment.