ladda-js / ladda

JavaScript data fetching layer with caching
https://petercrona.gitbooks.io/ladda/content/
MIT License
112 stars 16 forks source link

When idFrom is 'ARGS', and no args present, throws error #7

Closed crcatala closed 6 years ago

crcatala commented 7 years ago

When idFrom is set to 'ARGS', api methods that don't require arguments ends up throwing errors.

For example:

getList.operation = 'READ';
getList.idFrom = 'ARGS';
function getList() {
  const url = `${BASE_URL}search?query=react&hitsPerPage=200`;
  return fetch(url)
    .then(response => response.json())
    .then(result => result.hits);
}

api.hackernews.getList().then(hits => this.list = hits);

Calling getList() throws:

Error: Value is missing id, tried to add to entity products

Interestingly, passing any arg (even though not used by the api method) will make the call work as intended. i.e api.hackernews.getList('hello').then(hits => this.list = hits)