From 82645b1e615dfca036f1ccd66f2ab2bd1b556146 Mon Sep 17 00:00:00 2001 From: Michael Beckemeyer Date: Mon, 15 Apr 2024 14:53:50 +0200 Subject: [PATCH] Use reactiveStruct to store todos --- playground/Playground.vue | 13 +---- playground/TodoItem.vue | 100 ++++++++++++++++++++++++++++++++++++++ playground/TodosModel.ts | 16 +++--- 3 files changed, 112 insertions(+), 17 deletions(-) create mode 100644 playground/TodoItem.vue diff --git a/playground/Playground.vue b/playground/Playground.vue index 16beaea..062cf54 100644 --- a/playground/Playground.vue +++ b/playground/Playground.vue @@ -2,6 +2,7 @@ import { ref } from "vue"; import { TodosModel } from "./TodosModel"; import { useReactiveSnapshot } from "./integration"; +import TodoItem from "./TodoItem.vue"; const model = new TodosModel(); const snapshot = useReactiveSnapshot(() => { @@ -47,17 +48,7 @@ function createTodo() { diff --git a/playground/TodoItem.vue b/playground/TodoItem.vue new file mode 100644 index 0000000..538720a --- /dev/null +++ b/playground/TodoItem.vue @@ -0,0 +1,100 @@ + + + diff --git a/playground/TodosModel.ts b/playground/TodosModel.ts index b878816..54ded6d 100644 --- a/playground/TodosModel.ts +++ b/playground/TodosModel.ts @@ -1,11 +1,18 @@ -import { computed, reactiveMap } from "@conterra/reactivity-core"; +import { computed, reactiveMap, reactiveStruct } from "@conterra/reactivity-core"; import { ReadonlyReactiveMap } from "@conterra/reactivity-core"; export interface Todo { - id: string; + readonly id: string; title: string; } +const Todo = reactiveStruct().define({ + id: { + writable: false + }, + title: {} +}); + let nextId = 1; export class TodosModel { @@ -14,10 +21,7 @@ export class TodosModel { addTodo(title: string): string { const id = String(nextId++); - this.#todos.set(id, { - id, - title - }); + this.#todos.set(id, new Todo({ id, title })); return id; }