Skip to content

Commit

Permalink
Properly receive parameters for fetchCollection method.
Browse files Browse the repository at this point in the history
Return conditional promises for async methods.
  • Loading branch information
rtibbles committed Jun 24, 2021
1 parent f46e595 commit 9b7fc95
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions kolibri/core/assets/src/api-resources/contentNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Resource } from 'kolibri.lib.apiResource';
import Store from 'kolibri.coreVue.vuex.store';
import urls from 'kolibri.urls';
import cloneDeep from '../cloneDeep';
import ConditionalPromise from '../conditionalPromise';

/**
* Type definition for Language metadata
Expand Down Expand Up @@ -115,12 +116,14 @@ export default new Resource({
cache: {},
fetchModel({ id }) {
if (this.cache[id]) {
return Promise.resolve(cloneDeep(this.cache[id]));
return ConditionalPromise.resolve(cloneDeep(this.cache[id]));
}
return this.client({ url: this.modelUrl(id) }).then(response => {
const promise = new ConditionalPromise();
promise._promise = this.client({ url: this.modelUrl(id) }).then(response => {
this.cacheData(response.data);
return response.data;
});
return promise;
},
cacheData(data) {
if (Array.isArray(data)) {
Expand All @@ -143,11 +146,13 @@ export default new Resource({
}
}
},
fetchCollection(params) {
return this.client({ url: this.collectionUrl(), params }).then(response => {
fetchCollection({ getParams: params }) {
const promise = new ConditionalPromise();
promise._promise = this.client({ url: this.collectionUrl(), params }).then(response => {
this.cacheData(response.data);
return response.data;
});
return promise;
},
/**
* A method to request paginated tree data from the backend
Expand Down

0 comments on commit 9b7fc95

Please sign in to comment.