Skip to content

Commit

Permalink
change parameters order in useValueIterator (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bloomca authored May 27, 2024
1 parent b3543d3 commit 41967bf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ function List() {
children: [
createElement("h1", { children: "list" }),
listState.useValueIterator<{ id: number; name: string }>(
{ key: "id" },
({ elementState }) => {
return createElement("div", {
children: [
Expand All @@ -143,8 +144,7 @@ function List() {
),
],
});
},
{ key: "id" }
}
),
],
});
Expand Down
26 changes: 12 additions & 14 deletions integration-tests/create-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,20 +412,18 @@ describe("createState", () => {
createElement("ul", {
"data-testid": "listComponent",
children: [
state.useValueIterator<Item>(
({ elementState }) =>
createElement(() => {
onUnmount(unmountSpy);
return createElement("li", {
children: [
elementState.useValueSelector(
(element) => element.text,
(text) => createElement("span", { children: text })
),
],
});
}),
{ key: "id" }
state.useValueIterator<Item>({ key: "id" }, ({ elementState }) =>
createElement(() => {
onUnmount(unmountSpy);
return createElement("li", {
children: [
elementState.useValueSelector(
(element) => element.text,
(text) => createElement("span", { children: text })
),
],
});
})
),
],
}),
Expand Down
16 changes: 8 additions & 8 deletions src/hooks/create-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export type State<ValueType> = {
): VelesElement | VelesComponent | VelesStringElement;
useAttribute(cb: (value: ValueType) => string): AttributeHelper;
useValueIterator<Element>(
options: {
key: string | ((options: { element: Element; index: number }) => string);
},
cb: (props: {
elementState: State<Element>;
index: number;
}) => VelesElement | VelesComponent,
options: {
key: string | ((options: { element: Element; index: number }) => string);
}
}) => VelesElement | VelesComponent
): VelesComponent | VelesElement;
getValue(): ValueType;
getPreviousValue(): undefined | ValueType;
Expand Down Expand Up @@ -157,13 +157,13 @@ function createState<T>(
},
// TODO: add a version with a selector
useValueIterator<Element>(
options: {
key: string | ((options: { element: any; index: number }) => string);
},
cb: (props: {
elementState: State<Element>;
index: number;
}) => VelesElement | VelesComponent,
options: {
key: string | ((options: { element: any; index: number }) => string);
}
}) => VelesElement | VelesComponent
) {
const children: [
VelesElement | VelesComponent,
Expand Down

0 comments on commit 41967bf

Please sign in to comment.