create-sanifyfe 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-sanifyfe",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Scaffold project Sanify baru — bun create sanifyfe",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,7 +1,7 @@
1
1
  // pages/todo-page.ts — halaman daftar todo
2
2
 
3
- import { component, html, signal } from "@sanify/core";
4
- import { todos, remaining, addTodo } from "../state/todos.ts";
3
+ import { component, html, signal, For } from "@sanify/core";
4
+ import { todos, remaining, addTodo, type Todo } from "../state/todos.ts";
5
5
  import "../components/todo-item.ts";
6
6
 
7
7
  component("todo-page", () => {
@@ -37,10 +37,15 @@ component("todo-page", () => {
37
37
  </div>
38
38
 
39
39
  <ul>
40
+ ${For(
41
+ () => todos(),
42
+ (todo: () => Todo) => html`<todo-item .todo=${todo}></todo-item>`,
43
+ { key: (t: Todo) => t.id },
44
+ )}
40
45
  ${() =>
41
46
  todos().length === 0
42
47
  ? html`<li class="text-slate-400 py-2">Belum ada tugas.</li>`
43
- : todos().map((t) => html`<todo-item .todo=${t}></todo-item>`)}
48
+ : null}
44
49
  </ul>
45
50
 
46
51
  <div class="mt-4 text-sm">
@@ -3,7 +3,7 @@
3
3
  import { computed, persisted } from "@sanify/core";
4
4
 
5
5
  export interface Todo {
6
- id: number;
6
+ id: string;
7
7
  text: string;
8
8
  done: boolean;
9
9
  }
@@ -17,13 +17,16 @@ export const remaining = computed(() => todos().filter((t) => !t.done).length);
17
17
  export function addTodo(text: string): void {
18
18
  const trimmed = text.trim();
19
19
  if (!trimmed) return;
20
- setTodos((prev) => [...prev, { id: Date.now(), text: trimmed, done: false }]);
20
+ setTodos((prev) => [
21
+ ...prev,
22
+ { id: crypto.randomUUID(), text: trimmed, done: false },
23
+ ]);
21
24
  }
22
25
 
23
- export function toggleTodo(id: number): void {
26
+ export function toggleTodo(id: string): void {
24
27
  setTodos((prev) => prev.map((t) => (t.id === id ? { ...t, done: !t.done } : t)));
25
28
  }
26
29
 
27
- export function removeTodo(id: number): void {
30
+ export function removeTodo(id: string): void {
28
31
  setTodos((prev) => prev.filter((t) => t.id !== id));
29
32
  }