Skip to content

Commit

Permalink
Merge pull request #389 from KleeGroup/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
GuenoleK authored Dec 15, 2016
2 parents 33c8dea + db20922 commit 69ecdbb
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 41 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
npm-debug.log
node_modules
dist
/application
/component
/definition
/dispatcher
/exception
/history
/list
/message
/network
/reference
/router
/search
/site-description
/store
/translation
/user
/util
index.js
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "focus-core",
"version": "2.0.0",
"version": "2.1.1",
"description": "Focus library core part.",
"main": "index.js",
"babel": {
Expand Down
24 changes: 17 additions & 7 deletions src/application/action-builder.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const dispatcher = require('../dispatcher');
const {manageResponseErrors} = require('../network/error-parsing');
const {isArray} = require('lodash/lang');
const {identity} = require('lodash/utility');
import dispatcher from '../dispatcher';
import {manageResponseErrors} from '../network/error-parsing';
import {isArray} from 'lodash/lang';
import {identity} from 'lodash/utility';

/**
* Method call before the service.
Expand Down Expand Up @@ -53,15 +53,25 @@ function _dispatchServiceResponse({node, type, status, callerId}, json){
*/
function _dispatchFieldErrors({node, callerId}, errorResult){
const isMultiNode = isArray(node);
const data = isMultiNode ? errorResult : {[node]: errorResult};
const data = {};
if(isMultiNode){
node.forEach((nd) => {
data[nd] = (errorResult || {})[nd] || null;
});
} else {
data[node] = errorResult;
}

const errorStatus = {
name: 'error',
isLoading: false
};
let newStatus = {};
if(isMultiNode){
node.forEach((nd)=>{newStatus[nd] = errorStatus; });
}else {
node.forEach((nd) => {
newStatus[nd] = errorStatus;
});
} else {
newStatus[node] = errorStatus;
}
dispatcher.handleServerAction({
Expand Down
2 changes: 1 addition & 1 deletion src/network/error-parsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function _treatGlobalErrors(responseJSON, options) {
allMessagesTypes.forEach((globalMessageConf)=>{
//Treat all the gloabe
let msgs = messages[globalMessageConf.name];
if (msgs !== undefined) {
if (msgs) {
globalMessagesContainer = [...globalMessagesContainer, ...msgs];
//To remove
_treatGlobalMessagesPerType(msgs, globalMessageConf.type);
Expand Down
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;
15 changes: 5 additions & 10 deletions src/store/CoreStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,11 @@ class CoreStore extends EventEmitter {
const hasData = currentStore.data.has(def);
if(hasData){
const rawData = currentStore.data.get(def);
//If the store node isn't an object, immutable solution are non sens.
if(isFunction(rawData) || !isObject(rawData)){
return rawData;
}
else {
const data = rawData.toJS();
if(!isEmpty(data)){
return data;
}
}
if(rawData && rawData.toJS){
const data = rawData.toJS();
return isEmpty(data) ? undefined : data;
}
return rawData;
}
return undefined;
};
Expand Down

0 comments on commit 69ecdbb

Please sign in to comment.