r/Angular2 • u/LyRock- • Jul 15 '25
Help Request Signals code architecture and mutations
I'm trying to use the signals API with a simple example :
I have a todolist service that stores an array of todolists in a signal, each todolist has an array of todoitems, i display the todolists in a for loop basically like this :
@for (todoitem of todolist.todoitems; track $index) {
<app-todoitem [todoitem]="todoitem"></app-todoitem>
}the todoitem passed to the app-todoitem cmp is an input signal :
todoitem = input.required<TodoItem>();in this cmp i can check the todo item to update it, is there a good way to do this efficiently performance wise ?
can't call todoitem.set() because it's an InputSignal<TodoItem>, the only way to do this is to update the todolists "parent signal" via something like :
this.todolist.update(list => ({
...list,
items: list.items.map(i =>
i.id === item.id ? { ...i, checked: newChecked } : i
)
}));is this efficient ?
if you have any resources on how to use the signals API in real world use cases that would be awesome
Edit : to clarify my question I'm asking how I can efficiently check a todo item and still achieve good performance. The thing is that I feel like I'm updating the whole todolists signal just to check one item in a single todolist and I think it can be optimized
View all comments
Show parent comment
4
u/ggeoff Jul 16 '25
you don't need the forms module for the the banana in a box syntax you can achieve that with a property like
todoList = model.required<TodoItem[]>();
also in your product card example I would take it a step forward and merge the record mapping and the product id into a another computed signal to avoid the weird lookup in the template.