From a functional programming view, where I must keep state. Which one of these two approaches is deemed safer? Or are they the same. Also if one is preferred over the other in FP, I'm guessing the variable reassignment.
1.
topics = {
...topics,
topic: { subscribers: [], registerCallback: callback }
};
2.
topics[topic] = { subscribers: [], registerCallback: callback }
The first approach would be create new object and then reassigning the variable. The second approach would be to mutate the object properties.
I do realise that spread does not do a deep copy, but that isn't the point of this question.