Second, identical findAll always returns an empty array
See original GitHub issueGreat project! We as a team are enjoying to work with this.
Description
For us there seems to be a small problem though. The first request goes fine and returns the right response. The second request, with the exact same parameters, however seems to return an array instead of the actual previous request. I’m expecting that this is a cache issue since doing.
I hope you can help us find the cause of this issue.
What I already tried
- Run
clear()
before the findAll - fixes the issue but no caching 😦 - Remove the deserializer from the model - didn’t help at all, same problem
Related code
package.json
{
"js-data": "^3.0.0-rc.9",
"js-data-http": "~3.0.0-rc.2"
}
store.js
import { DataStore } from 'js-data';
import { HttpAdapter } from 'js-data-http';
const store = new DataStore();
// Instantiate the HttpAdapter
const adapter = new HttpAdapter({
basePath: '/v1'
});
// Register the adapter with the Mapper
store.registerAdapter('http', adapter, { 'default': true });
export default store;
user.js
import store from './store';
store.defineMapper('User', {
endpoint: '/users',
deserialize (resourceConfig, response) {
return response.data.user || response.data.users;
},
methods: {
fullName () {
return this.firstname + ' ' + this.surname;
}
}
});
const User = store.as('User');
export default User;
findAll request
import User from 'models/user';
let users;
let meta;
// params.query is a dynamic string based on an search input
let params = {
per_page: 20,
page: 1,
query: null
};
User.findAll(params, { raw: true })
.then((response) => {
meta = JSON.parse(response.request.response).meta;
users = response.data;
})
.catch((error) => {
console.error(error);
});
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Empty list returned from ElementTree findall - Stack Overflow
I'm new to xml parsing and Python so bear with me. I'm using lxml to parse a wiki dump, but I just want...
Read more >Methods of RegExp and String - The Modern JavaScript Tutorial
If the regexp has flag g , then it returns an array of all matches as strings, without capturing groups and other details....
Read more >How to clone an array in JavaScript - freeCodeCamp
map returns an array of the same length every single time. To double a list of numbers, use map with a double function....
Read more >Create empty array of specified class - MATLAB ... - MathWorks
Use this syntax to define an empty array that is the same size as an existing empty array. Pass the values returned by...
Read more >Underscore.js
Given an array of arrays, returns a series of new arrays, the first of which contains all of the first elements in the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@brodie-g’s approach is actually quite nice. I ended up doing something similar in my project. To add up onto that you might have issues with cache if you have a SPA running though, since removing records won’t actually works.
So to add up onto that solution we did this:
We are running this in a production app without any problems by now. Personally I’m all happy with this solution. 😄
@bbthorntz: I think this is something that JSData should do by itself right? In my mind it doesn’t make a whole lot of sense that it suddenly returns an empty array because of cache. If JSData finds a cached response with the same parameters it should return the cached data, not an empty array.
For me in the specific situation described in the issue I was able to use
force: true
. But I can imagine how this is not always a valid scenario.