I’ve been working on using signals more often than not and have run into a use case where I can’t find a reasonable answer.
Many of the examples and guides online show creating a signal with a single value and updating it through .set() or .update(). For example:
public value = signal<int>(0); value.set(1);
Which makes perfect sense with simple inputs, but what happens when we want to use a signal with an object that has multiple values? Or we want multiple inputs? For example, if I have a User object
export interface User { firstName: string, lastName: string }
And that object is inside of a signal,
public currentUser = signal<User>({firstName: 'Doug', lastName: 'The Cat'});
And I want to have a form for users to update their name, how would I update the individual values without completely overwriting the existing user object?
I’ve tried creating a shallow copy of the signals output to then attach the form to and then calling set on the signal to update the properties but that feels off since I’m just overwriting what’s there.
I also thought about turning each value, firstName, lastName into their own signals, but that would get out of hand really fast as values get added to the object like streetAddress, poBox, etc.