Skip to content

Commit

Permalink
Fix small bugs in TodoMVC
Browse files Browse the repository at this point in the history
  • Loading branch information
paldepind committed Aug 28, 2019
1 parent 5038df4 commit f221ed0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
18 changes: 6 additions & 12 deletions examples/todo/src/TodoApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ type FromView = {
// A behavior representing the current value of the localStorage property
const todoListStorage = itemBehavior("todoList");

const getCompletedIds = (outputs: H.Behavior<ItemOut[]>) =>
const getCompletedIds = (outputs: H.Behavior<ItemOut[]>, completed: boolean) =>
H.moment((at) => {
return at(outputs)
.filter((o) => at(o.completed))
.filter((o) => at(o.completed) === completed)
.map((o) => o.id);
});

Expand Down Expand Up @@ -70,7 +70,8 @@ export const app = component<FromView>(
list.length > 0 ? combine(...list.map((o) => o.destroyItemId)) : H.empty
)
);
const completedIds = getCompletedIds(on.itemOutputs);
const completedIds = getCompletedIds(on.itemOutputs, true);
const uncompletedIds = getCompletedIds(on.itemOutputs, false);

const savedTodoName: ItemParams[] = yield H.sample(todoListStorage);
const restoredTodoName = savedTodoName === null ? [] : savedTodoName;
Expand All @@ -93,13 +94,6 @@ export const app = component<FromView>(
H.changes(todoNames).map((n) => setItemIO("todoList", n))
);

const areAllCompleted = H.lift(
(a, b) => a.length === b.length,
completedIds,
on.itemOutputs
);
const areAnyCompleted = completedIds.map(isEmpty).map((b) => !b);

// Strip the leading `/` from the hash location
const currentFilter = locationHashB.map((s) => s.slice(1));
const hidden = todoNames.map(isEmpty);
Expand All @@ -122,7 +116,7 @@ export const app = component<FromView>(
checkbox({
class: "toggle-all",
attrs: { id: "toggle-all" },
props: { checked: areAllCompleted }
props: { checked: uncompletedIds.map(isEmpty) }
}).use({ toggleAll: "checkedChange" }),
label({ attrs: { for: "toggle-all" } }, "Mark all as complete"),
ul(
Expand All @@ -142,7 +136,7 @@ export const app = component<FromView>(
),
todoFooter({
itemsLeft,
areAnyCompleted,
noneAreCompleted: completedIds.map(isEmpty),
currentFilter,
hidden
}).use({ clearCompleted: "clearCompleted" })
Expand Down
4 changes: 2 additions & 2 deletions examples/todo/src/TodoFooter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { span, button, ul, li, a, footer, strong } = elements;
export type Props = {
currentFilter: H.Behavior<string>;
itemsLeft: H.Behavior<number>;
areAnyCompleted: H.Behavior<boolean>;
noneAreCompleted: H.Behavior<boolean>;
hidden: H.Behavior<boolean>;
};

Expand Down Expand Up @@ -39,7 +39,7 @@ const todoFooter = (props: Props) =>
filterItem("Completed", "completed", props.currentFilter)
]),
button(
{ class: ["clear-completed", { hidden: props.areAnyCompleted }] },
{ class: ["clear-completed", { hidden: props.noneAreCompleted }] },
"Clear completed"
).use({ clearCompleted: "click" })
])
Expand Down

0 comments on commit f221ed0

Please sign in to comment.