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

Cleanup errors from ContentNodeResource changes #8174

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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