Skip to content

Conversation

@theninj4
Copy link
Contributor

@theninj4 theninj4 commented Jun 7, 2016

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.

@connormeredith
Copy link

Taking review ☝️

};

MemoryStore.prototype._clone = function(obj) {
return JSON.parse(JSON.stringify(obj));
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

@pmcnr-hx pmcnr-hx Jun 7, 2016

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) {

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?

Copy link
Contributor Author

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.

@connormeredith
Copy link

Minor comment, otherwise it's looking good 👍

@pmcnr-hx
Copy link
Contributor

pmcnr-hx commented Jun 9, 2016

👍 :shipit: I'm so happy you've implemented that MemoryStore._indexOf helper function. 🦄

@theninj4 theninj4 merged commit 7dff9d3 into master Jun 9, 2016
@theninj4 theninj4 deleted the memory-store-clone branch June 22, 2016 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants