Skip to content

Commit

Permalink
Merge pull request #383 from KleeGroup/cherry-pick-cav
Browse files Browse the repository at this point in the history
Reporting cav changes to develop
  • Loading branch information
TomGallon authored Dec 13, 2016
2 parents 098a887 + 2c19d8d commit bebdacc
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 22 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
npm-debug.log
node_modules
dist
/application
/component
/definition
/dispatcher
/exception
/history
/list
/message
/network
/reference
/router
/search
/site-description
/store
/translation
/user
/util
39 changes: 39 additions & 0 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/reference/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ function loadList(listDesc) {
* @param {string} listName - The name of the list to load.
* @param {object} args - Argument to provide to the function.
*/
function loadListByName(listName, args) {
function loadListByName(listName, args, skipCache = false) {
checkIsString('listName', listName);
const configurationElement = getElement(listName);
if (typeof configurationElement !== `function`) {
throw new Error(`You are trying to load the reference list: ${listName} which does not have a list configure.`);
}
let now = _getTimeStamp();
if(cache[listName] && (now - cache[listName].timeStamp) < getCacheDuration()) {
if(cache[listName] && (now - cache[listName].timeStamp) < getCacheDuration() && !skipCache) {
_deletePromiseWaiting(listName);
//console.info('data served from cache', listName, cache[listName].value);
return Promise.resolve(cache[listName].value);
Expand All @@ -70,7 +70,7 @@ function loadListByName(listName, args) {
//Load many lists by their names. `refHelper.loadMany(['list1', 'list2']).then(success, error)`
// Return an array of many promises for all the given lists.
// Be carefull, if there is a problem for one list, the error callback is called.
function loadMany(names) {
function loadMany(names, skipCache = false) {
if(names === undefined){
return [];
}
Expand All @@ -82,7 +82,7 @@ function loadMany(names) {
return acc;
}
promiseWaiting.push(name);
return acc.concat([loadListByName(name)]);
return acc.concat([loadListByName(name, null, skipCache).then(dataList => ({name, dataList: dataList}))]);
}, []);
}
/**
Expand Down
33 changes: 15 additions & 18 deletions src/reference/built-in-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@ var dispatcher = require('../dispatcher');
* @param {array} referenceNames - An array which contains the name of all the references to load.
* @returns {Promise} - The promise of loading all the references.
*/
function builtInReferenceAction(referenceNames){
return function(){
if(!referenceNames){
return undefined;
}
return Promise.all(loadManyReferenceList(referenceNames))
.then(function successReferenceLoading(data){
//Rebuilt a constructed information from the map.
var reconstructedData = {};
referenceNames.map((name, index)=>{
reconstructedData[name] = data[index];
});
//
dispatcher.handleViewAction({data: reconstructedData, type: 'update', subject: 'reference'});
}, function errorReferenceLoading(err){
dispatcher.handleViewAction({data: err, type: 'error'});
});
};
function builtInReferenceAction(referenceNames, skipCache = false) {
return () => {
if(!referenceNames) {
return undefined;
}
return Promise.all(loadManyReferenceList(referenceNames, skipCache))
.then(function successReferenceLoading(data) {
//Rebuilt a constructed information from the map.
const reconstructedData = data.reduce((acc,item) => {acc[item.name] = item.dataList; return acc;}, {})
dispatcher.handleViewAction({data: reconstructedData, type: 'update', subject: 'reference'});
}, function errorReferenceLoading(err) {
dispatcher.handleViewAction({data: err, type: 'error'});
});
};
}


module.exports = builtInReferenceAction;

0 comments on commit bebdacc

Please sign in to comment.