Skip to content

Commit

Permalink
fixed pop in Each component
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishiv committed Jun 24, 2024
1 parent 759c2f4 commit 181de6c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
19 changes: 14 additions & 5 deletions examples/kitchen-sink/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,25 @@ export const Todos = component("Todos", (props, { signal, wire, store }) => {
style="width: 100%; max-width: 400px;"
/>
</form>
<a
href="#"
onClick={(e) => {
e.preventDefault();
produce($todos.items, (items) => {
//items.splice(0, 0, json);
items.pop();
});
}}
>
remove first(pop)
</a>
<ul>
<Each
cursor={$todos.items}
renderItem={(cursor, i) => {
const v = reify(cursor);
return (
<li key={i}>
<li key={i + ""}>
<span style="padding: 0 4px 0 0 ;">
<button
onClick={(e) => {
Expand All @@ -112,13 +124,10 @@ export const Todos = component("Todos", (props, { signal, wire, store }) => {
);
});

const Test = component("Test", (props, utils) => {
return <div key="1">hey</div>;
});

export const Layout = component<{}>(
"Layout",
(props, { signal, wire, api }) => {
//return <Todos />;
const $count = signal("count", 0);
const $doubleCount = wire(($) => $count($) * 2); // explicit subscription

Expand Down
10 changes: 6 additions & 4 deletions src/stdlib/Each/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,22 @@ export const Each: <T extends ArrayOrObject>(
//console.debug("change", changes, path);

// console.log("list change", data, path, value);
const pStep = parentStep.children[0];
if (data.name == "push") {
const index = (data.result as number) - 1; // push returns index
const { treeStep, el } = renderArray(
parentStep,
pStep,
props.renderItem,
cursor,
value,
index
);
const previousChildren = [...parentStep.children];

const { registry, root } = reifyTree(renderContext, el, parentStep);
addNode(renderContext, parentStep, root);
addNode(renderContext, pStep, root);
} else if (data.name === "pop") {
const previousChildren = [...parentStep.children];
if (!pStep || !pStep.children) return;
const previousChildren = [...pStep.children];
const firstNode = previousChildren[0];
if (firstNode) removeNode(renderContext, firstNode);
} else if (data.name === "splice") {
Expand Down

0 comments on commit 181de6c

Please sign in to comment.