MCPcopy Index your code
hub / github.com/TanStack/db / App

Class App

examples/angular/todos/src/app/app.ts:139–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137 `,
138})
139export class App {
140 projects = [
141 { id: 1, name: 'Work' },
142 { id: 2, name: 'Home' },
143 ]
144
145 selectedProjectId = signal(2)
146
147 todoQuery = injectLiveQuery({
148 params: () => ({ projectID: this.selectedProjectId() }),
149 query: ({ params, q }) =>
150 q.from({ todo: todosCollection }).where(({ todo }) => eq(todo.projectID, params.projectID)),
151 })
152
153 newTodoText = ''
154
155 addTodo() {
156 if (!this.newTodoText.trim()) return
157
158 const newTodo = {
159 id: Date.now(),
160 text: this.newTodoText.trim(),
161 projectID: this.selectedProjectId(),
162 completed: false,
163 created_at: new Date(),
164 }
165
166 todosCollection.insert(newTodo)
167 this.newTodoText = ''
168 }
169
170 toggleTodo(id: number) {
171 todosCollection.update(id, (draft: any) => {
172 draft.completed = !draft.completed
173 })
174 }
175
176 deleteTodo(id: number) {
177 todosCollection.delete(id)
178 }
179
180 getCompletedCount(): number {
181 return this.todoQuery.data().filter((todo) => todo.completed).length
182 }
183}

Callers

nothing calls this directly

Calls 4

injectLiveQueryFunction · 0.90
eqFunction · 0.90
whereMethod · 0.80
fromMethod · 0.80

Tested by

no test coverage detected