Skip to content
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

Changed the getBootstrappedData function to add each model of a collection to the modelStore #380

Closed

Conversation

saponifi3d
Copy link
Contributor

Added each model that's part of a collection to the bootstrappedData - this way we can access them singularly without having to request the single model inside of the collection.

This also fixes an issue if there were two models with a sub-model of the same key.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 1c332e1 on saponifi3d:parse-collections-models into 38dc8be on rendrjs:master.

_.each(list, function (value, key) {
if (app.modelUtils.isModel(value) || app.modelUtils.isCollection(value)) {
var tempObject = {},
key = (key !== value.cid && isNaN(parseInt(key))) ? key : value.cid;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I see what this line is doing, but it's pretty opaque and took me a long time to figure out.

I'm reading it as... if the key is neither a number nor the model cid, use it as is. Otherwise use the cid.
So the case in which we used the cid is either the key is a number or it is the cid... So basically, in the case of a collection, where our keys are numbers, store the model at the root level of the hash using it's cid as a key. Otherwise you could see overwriting among collections.

Are there any other cases this is happening in? If not, I'd prefer it be made more explicit, something like
if (app.modelUtils.isCollection(modelOrCollection) {key = value.cid;}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here was that if you have a named field you'd want it to appear in the cache as such. Best course of action might be to change the key to be model_name:id: the same way as everything is currently cached.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) when pulling 75f74c8 on saponifi3d:parse-collections-models into 38dc8be on rendrjs:master.

@mdimas
Copy link
Contributor

mdimas commented Jul 30, 2014

Looks like a pretty straightforward extension of #372 for collections. 👍

@saponifi3d
Copy link
Contributor Author

This PR is no longer required because we are parsing the objects client-side, which is also setting up the cache as we would expect.

@saponifi3d saponifi3d closed this Nov 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants