-
Notifications
You must be signed in to change notification settings - Fork 114
Clone all objects passing in-to and out-of the in memory store #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Taking review ☝️ |
| }; | ||
|
|
||
| MemoryStore.prototype._clone = function(obj) { | ||
| return JSON.parse(JSON.stringify(obj)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure we never have circular references?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This data is intended to be serialised at this point for storage. If anything does have a circular reference at this point, it's going to break for real when the memory handler gets replaced for a real storage mechanism?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we don't really need the MemoryStore object instance here, I am wondering if this shouldn't simply me a module level helper function, i.e., MemoryStore._clone. Alternatively it could also be implemented as a resource method...
| }); | ||
| }; | ||
|
|
||
| MemoryStore._clone = function(obj) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for not using lodash's cloneDeep?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd mean adding another dependency for something we really don't need.
|
Minor comment, otherwise it's looking good 👍 |
|
👍 |
We've had some issues with stubbing journey tests via the memory handler, and they boil down to how the memory handler doesn't clone objects passing through it. This PR ensures all objects get cloned to allow us to mutate resources without effecting the data in the store.