I am wondering about one architectural problem.
Suppose I have several calls from api, at different times, that return me different objects and arrays. In these requests, sometimes there are the same objects whose key is id. I map them to class to have methods for them.
Should I make these objects have the same reference? Then it would be more convenient to call methods on these objects and they would update throughout the system. On the other hand it could cause some unexpected side effects.
How do you deal with such a problem? Do you have a general list of objects of a given type in your store and retrieve a reference from it when you need to assign it to another object? Or maybe you do not care about it, and even though it is theoretically one object with a given id, there are copies of it all over the system?
Or maybe you do not have nested objects and e.g. in the Car object there is only the engineId prop to search for it in the whole list?