You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When transitioning a model using Command.NextState -> commands.State, is it dangerous to share pointers or reference types between model states?
For example,
type State struct {
index map[string]string
}
func (writeFooBarCommand) NextState(s commands.State) commands.State {
current := s.(State)
next := current
next.index["foo"] = "bar"
return next
}
I believe that the existing model state and the new model state will share a reference to the underlying map, meaning manipulations via the old state instance or the new state instance will reflect in both objects. I currently make it a habit to deep copy my model states when transitioning, but my question is whether or not the deep copy is necessary.
The text was updated successfully, but these errors were encountered:
When transitioning a model using
Command.NextState -> commands.State
, is it dangerous to share pointers or reference types between model states?For example,
I believe that the existing model state and the new model state will share a reference to the underlying map, meaning manipulations via the old state instance or the new state instance will reflect in both objects. I currently make it a habit to deep copy my model states when transitioning, but my question is whether or not the deep copy is necessary.
The text was updated successfully, but these errors were encountered: