Current section
Files
Jump to
Current section
Files
src/legos@keyed.erl
-module(legos@keyed).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/legos/keyed.gleam").
-export([el/2, row/2, column/2]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-file("src/legos/keyed.gleam", 18).
?DOC(
" Create a keyed element that helps optimize cases where children are getting\n"
" added, moved, removed, etc. Common examples include:\n"
"\n"
" - The user can delete items from a list\n"
" - The user can create new items in a list\n"
" - You can sort a list based on name or date or whatever\n"
"\n"
" When you use a keyed element, every child is paired with a string identifier.\n"
" This makes it possible for the underlying diffing algorithm to reuse nodes\n"
" more efficiently.\n"
"\n"
" This means if a key is changed between renders, then the diffing step will\n"
" be skipped and the node will be forced to rerender.\n"
).
-spec el(
list(legos@internal@model:attribute(legos@internal@model:aligned(), XAJ)),
{binary(), legos@internal@model:element(XAJ)}
) -> legos@internal@model:element(XAJ).
el(Attrs, Child) ->
legos@internal@model:element(
as_el,
generic,
[legos@ui:width(legos@ui:shrink()),
legos@ui:height(legos@ui:shrink()) |
Attrs],
{keyed, [Child]}
).
-file("src/legos/keyed.gleam", 32).
?DOC(
" Create a keyed row layout with a list of keyed children.\n"
" Each child is paired with a string key for efficient diffing.\n"
).
-spec row(
list(legos@internal@model:attribute(legos@internal@model:aligned(), XAO)),
list({binary(), legos@internal@model:element(XAO)})
) -> legos@internal@model:element(XAO).
row(Attrs, Children) ->
legos@internal@model:element(
as_row,
generic,
[legos@internal@model:html_class(
<<<<(<<"cl"/utf8>>)/binary, " "/utf8>>/binary,
(<<"ccy"/utf8>>)/binary>>
),
legos@ui:width(legos@ui:shrink()),
legos@ui:height(legos@ui:shrink()) |
Attrs],
{keyed, Children}
).
-file("src/legos/keyed.gleam", 53).
?DOC(
" Create a keyed column layout with a list of keyed children.\n"
" Each child is paired with a string key for efficient diffing.\n"
).
-spec column(
list(legos@internal@model:attribute(legos@internal@model:aligned(), XAU)),
list({binary(), legos@internal@model:element(XAU)})
) -> legos@internal@model:element(XAU).
column(Attrs, Children) ->
legos@internal@model:element(
as_column,
generic,
[legos@internal@model:html_class(
<<<<(<<"ct"/utf8>>)/binary, " "/utf8>>/binary,
(<<"cl"/utf8>>)/binary>>
),
legos@ui:height(legos@ui:shrink()),
legos@ui:width(legos@ui:shrink()) |
Attrs],
{keyed, Children}
).