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

DS#find() returns items cached with DS#inject() #118

Merged
merged 1 commit into from
Apr 14, 2015

Conversation

mightyguava
Copy link
Contributor

DS#find() currently only returns the cached item early only if a
previous request was made to fetch the item. If the item was added using
DS#inject(), DS#find() will make a request anyways. This makes DS#find()
return the item directly instead.

@jmdobry
Copy link
Member

jmdobry commented Apr 14, 2015

I hesitate to call the current behavior a bug, so I am not keen on making this change as it would be a breaking change. As recently discussed in #117, we actually want to make this configurable. By making it configurable, we can avoid a breaking change, but allow you to achieve the behavior that this PR implements. In js-data 2.0 we can make the breaking change have the default behavior be that find will immediately resolve if an item was injected manually into the store.

So, can you make one more commit to your branch that adds a configuration option called findStrictCache that defaults to true? You can add it right below findBelongsTo here.

Then, the boolean expression in DS#find should be if ((!options.findStrictCache || id in resource.completedQueries) && _this.get(resourceName, id)) {

So, until 2.0 when I remove the option and change behavior, in your own app you can set findStrictCache to false.

Thanks!

@mightyguava
Copy link
Contributor Author

Oops, I saw the bug but the title totally didn't register as relevant. Will make it configurable.

DS#find() currently only returns the cached item early only if a
previous request was made to fetch the item. If the item was added using
DS#inject(), DS#find() will make a request anyways.

This adds a findStrictCache option that can be set to false to make
DS#find() return the item directly instead.
@mightyguava
Copy link
Contributor Author

Updated.

Btw, my use case is mostly for testing, so making this an option really does make a lot of sense. It's quite convenient to use DS#inject() to set up a mock data set and set findStrictCache to false to prevent lookups.

@jmdobry
Copy link
Member

jmdobry commented Apr 14, 2015

Awesome!

jmdobry added a commit that referenced this pull request Apr 14, 2015
DS#find() returns items cached with DS#inject()
@jmdobry jmdobry merged commit 6e974be into js-data:master Apr 14, 2015
jmdobry added a commit that referenced this pull request Apr 14, 2015
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.

None yet

2 participants