diff --git a/.gitignore b/.gitignore index a3c7ccf..73b849f 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/package.json b/package.json index 8994a6a..e6d6683 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "focus-core", - "version": "2.0.0", + "version": "2.1.1", "description": "Focus library core part.", "main": "index.js", "babel": { diff --git a/src/application/action-builder.js b/src/application/action-builder.js index e89e2a8..563d275 100644 --- a/src/application/action-builder.js +++ b/src/application/action-builder.js @@ -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. @@ -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({ diff --git a/src/network/error-parsing.js b/src/network/error-parsing.js index c1662c2..719393c 100644 --- a/src/network/error-parsing.js +++ b/src/network/error-parsing.js @@ -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); diff --git a/src/reference/builder.js b/src/reference/builder.js index 4c97a09..9675911 100755 --- a/src/reference/builder.js +++ b/src/reference/builder.js @@ -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); @@ -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 []; } @@ -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}))]); }, []); } /** diff --git a/src/reference/built-in-action.js b/src/reference/built-in-action.js index 32adcfb..c440f7c 100644 --- a/src/reference/built-in-action.js +++ b/src/reference/built-in-action.js @@ -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; diff --git a/src/store/CoreStore.js b/src/store/CoreStore.js index 058d654..1df5ab4 100644 --- a/src/store/CoreStore.js +++ b/src/store/CoreStore.js @@ -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; };