From 9b7fc957da15b26bb88cfaa33065ad2b36ef91ca Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Thu, 24 Jun 2021 11:21:46 -0700 Subject: [PATCH] Properly receive parameters for fetchCollection method. Return conditional promises for async methods. --- .../core/assets/src/api-resources/contentNode.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kolibri/core/assets/src/api-resources/contentNode.js b/kolibri/core/assets/src/api-resources/contentNode.js index a98ce7c1d54..5afb1985fcf 100644 --- a/kolibri/core/assets/src/api-resources/contentNode.js +++ b/kolibri/core/assets/src/api-resources/contentNode.js @@ -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 @@ -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)) { @@ -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