From 8ec605499d67cc005b5b77b59b6e6c68039eef01 Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Fri, 21 Aug 2015 22:38:31 +0200 Subject: [PATCH 01/24] [eslint] clean application/clear --- src/application/clear.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/application/clear.js b/src/application/clear.js index 367846e..04a4982 100644 --- a/src/application/clear.js +++ b/src/application/clear.js @@ -1,5 +1,5 @@ -let React = require('react'); -var mountedComponents = require('./mounted-components'); +const React = require('react'); +let mountedComponents = require('./mounted-components'); /** * Clear a react component. From bbed756e3843510bcf320f408777489c182eb34b Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Fri, 21 Aug 2015 22:44:54 +0200 Subject: [PATCH 02/24] [eslint] fix application index --- src/application/index.js | 75 ++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 29 deletions(-) diff --git a/src/application/index.js b/src/application/index.js index 46e0fb3..ed2547f 100644 --- a/src/application/index.js +++ b/src/application/index.js @@ -1,33 +1,50 @@ -let React = require('react'); -var dispatcher = require('../dispatcher'); -var Empty = React.createClass({ - render: function() { - return
; - } +const React = require('react'); +const dispatcher = require('../dispatcher'); +//Empty compoennt. +const Empty = React.createClass({ + /** @inheritdoc */ + displayName: 'Empty', + /** @inheritdoc */ + render() { + return
; + } }); module.exports = { - render: require('./render'), - builtInStore: require('./built-in-store'), - actionBuilder: require('./action-builder'), - clear: require('./clear'), - mountedComponents: require('./mounted-components'), - changeMode(newMode, previousMode){ - var mode = {newMode: newMode, previousMode: previousMode}; - dispatcher.handleViewAction({data: {mode: mode}, type: 'update'}); - }, - changeRoute(newRoute){ - dispatcher.handleViewAction({data: {route: newRoute}, type: 'update'}); - }, - clearCartridge(){ - dispatcher.handleViewAction({ - data: { - cartridgeComponent: {component: Empty}, - barContentLeftComponent: {component: Empty}, - summaryComponent: {component: Empty}, - actions: {primary: [], secondary: []} - }, - type: 'update' - }); - } + render: require('./render'), + builtInStore: require('./built-in-store'), + actionBuilder: require('./action-builder'), + clear: require('./clear'), + mountedComponents: require('./mounted-components'), + /** + * Change application mode. + * @param {string} newMode - New application mode. + * @param {string} previousMode - Previous mode. + */ + changeMode(newMode, previousMode){ + const mode = {newMode: newMode, previousMode: previousMode}; + dispatcher.handleViewAction({data: {mode: mode}, type: 'update'}); + }, + /** + * Change application route (maybe not the wole route but a route's group.) + * @param {string} newRoute - new route name. + */ + changeRoute(newRoute){ + dispatcher.handleViewAction({data: {route: newRoute}, type: 'update'}); + }, + /** + * Clear the application's header. + * @return {[type]} [description] + */ + clearHeader(){ + dispatcher.handleViewAction({ + data: { + cartridgeComponent: {component: Empty}, + barContentLeftComponent: {component: Empty}, + summaryComponent: {component: Empty}, + actions: {primary: [], secondary: []} + }, + type: 'update' + }); + } }; From 047a45ab3641d459f9cd0bee2e82e967ad6dbf86 Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Fri, 21 Aug 2015 22:47:26 +0200 Subject: [PATCH 03/24] [eslint] clean application/render --- src/application/render.js | 65 +++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/src/application/render.js b/src/application/render.js index 26b8a6f..81cc9cf 100644 --- a/src/application/render.js +++ b/src/application/render.js @@ -1,40 +1,37 @@ -'use strict'; /*global document*/ - var React = require('react'); -var keys = require('lodash/object/keys'); -/** - * Map containing all the mounted components. - * @type {Object} - */ -var mountedComponents = require('./mounted-components'); - -var clearComponent = require('./clear'); +//dependencies +const React = require('react'); +const keys = require('lodash/object/keys'); +const mountedComponents = require('./mounted-components'); +const clearComponent = require('./clear'); /** - * Render a react component in a DOM selector. - * @param {object} component - A react component. - * @param {string} selector - A selector on a DOM node. - * @param {object} options - Options for the component rendering. - */ +* Render a react component in a DOM selector. +* @param {object} component - A react component. +* @param {string} selector - A selector on a DOM node. +* @param {object} options - Options for the component rendering. +*/ module.exports = function renderComponent(component, selector, options){ - options = options || {}; - // Clear a potential previously mounted component - clearComponent(selector); - let targetDOMContainer = document.querySelector(selector); - if(!targetDOMContainer){throw new Error(`You are trying to render a component in a DOM element which is not existing, your selector is ${selector}`); } - // Render the component - var mountedComponent = React.render( - React.createElement(component, options.props, options.data), - targetDOMContainer - ); - //Save the fact that a component is mounted. - mountedComponents[selector] = mountedComponent; - console.info('Mounted components : ', keys(mountedComponents)); - return mountedComponent; + options = options || {}; + // Clear a potential previously mounted component + clearComponent(selector); + const targetDOMContainer = document.querySelector(selector); + if(!targetDOMContainer){ + throw new Error(`You are trying to render a component in a DOM element which is not existing, your selector is ${selector}`); + } + // Render the component + const mountedComponent = React.render( + React.createElement(component, options.props, options.data), + targetDOMContainer + ); + //Save the fact that a component is mounted. + mountedComponents[selector] = mountedComponent; + console.info('Mounted components : ', keys(mountedComponents)); + return mountedComponent; }; /* - Exemple - var render = Focus.application.render; - var MyComponent = require('./my-component'); - render(MyComponent, 'div.component-container', {props: {id: '12'}}); - */ +Exemple +var render = Focus.application.render; +var MyComponent = require('./my-component'); +render(MyComponent, 'div.component-container', {props: {id: '12'}}); +*/ From 6ffc7acc4507147683b53cde05d72bbd0fca4547 Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Fri, 21 Aug 2015 22:51:04 +0200 Subject: [PATCH 04/24] [eslint] clean component/builder --- src/component/builder.js | 46 ++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/src/component/builder.js b/src/component/builder.js index 0144d77..54831a3 100644 --- a/src/component/builder.js +++ b/src/component/builder.js @@ -1,40 +1,30 @@ -"use strict"; -var React = require('react'); -var assign = require('object-assign'); +const React = require('react'); +const assign = require('object-assign'); //var isObject = require('lodash/lang/isObject'); //var isFunction = require('lodash/lang/isFunction'); /** - * Create a component with a mixin except id the component is mixin only. - * @param {object} mixin - The component mixin. - * @param {Boolean} isMixinOnly - define if the component is a mixin only. - * @return {object} - {component} the built react component. - */ +* Create a component with a mixin except id the component is mixin only. +* @param {object} mixin - The component mixin. +* @param {Boolean} isMixinOnly - define if the component is a mixin only. +* @return {object} - {component} the built react component. +*/ function createComponent(mixin, isMixinOnly){ if (isMixinOnly){ - return undefined;//Error('Your class publish a mixin only...'); + return null; } return {component: React.createClass(mixin)}; } /** - * Build a module with a mixin and a React component. - * @param {object} componentMixin - Mixin of the component. - * @param {boolean} isMixinOnly - Bolean to set . - * @return {object} {mixin: 'the component mixin', component: 'the react instanciated component'} - */ -module.exports = function(componentMixin, isMixinOnly){ - - return assign( { - mixin: componentMixin - /*extend: function extendMixin(properties){ - if(isFunction(componentMixin)){ - throw new Error('You cannot extend a mixin function'); - } - if(!isObject(properties)){ - throw new Error('properties should be an object'); - } - return assign({}, componentMixin, properties); - },*/ - }, createComponent(componentMixin, isMixinOnly)); +* Build a module with a mixin and a React component. +* @param {object} componentMixin - Mixin of the component. +* @param {boolean} isMixinOnly - Bolean to set . +* @return {object} {mixin: 'the component mixin', component: 'the react instanciated component'} +*/ +module.exports = function builder(componentMixin, isMixinOnly){ + return assign( + {mixin: componentMixin}, + createComponent(componentMixin, isMixinOnly) + ); }; From c9726c95b330f17ff0a8a6c40f2977b6281659ee Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Fri, 21 Aug 2015 22:51:25 +0200 Subject: [PATCH 05/24] [eslint] clean component/index --- src/component/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/component/index.js b/src/component/index.js index 60b1e75..3fabe93 100644 --- a/src/component/index.js +++ b/src/component/index.js @@ -1,4 +1,3 @@ -"use strict"; module.exports = { builder: require('./builder'), types: require('./types') From c1585cbe4b29630525091b721f0b19fa4a62b228 Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Fri, 21 Aug 2015 22:53:01 +0200 Subject: [PATCH 06/24] [remove] component/override --- src/component/override.js | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 src/component/override.js diff --git a/src/component/override.js b/src/component/override.js deleted file mode 100644 index f071618..0000000 --- a/src/component/override.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = function(fn, args, context){ - context = context || this; - if(context.fn){ - console.log('test'); - } -}; From aad443f385825cb697812fd73346157b15127f54 Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Fri, 21 Aug 2015 22:56:47 +0200 Subject: [PATCH 07/24] [eslint] clean component/types --- src/component/types.js | 63 +++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/src/component/types.js b/src/component/types.js index b3886bf..8906be7 100644 --- a/src/component/types.js +++ b/src/component/types.js @@ -1,36 +1,35 @@ -"use strict"; //Dependencies. -var React = require('react'); -var isString = require('lodash/lang/isString'); -var isArray = require('lodash/lang/isArray'); +const React = require('react'); +const isString = require('lodash/lang/isString'); +const isArray = require('lodash/lang/isArray'); /** - * Expose a React type validation for the component properties validation. - * @see http://facebook.github.io/react/docs/reusable-components.html - * @param {string} type - String or array of the types to use. - * @param {boolean} isRequired - Defines if the props is mandatory. - * @returns {object} The corresponding react type. - */ -module.exports = function(type, isRequired){ - var isStringType = isString(type); - if(!isStringType && !isArray(type)){ - throw new Error('The type should be a string or an array'); - } - //Container for the propTypes. - var propTypeToReturn; - //Array case. - if(isStringType){ - propTypeToReturn = React.PropTypes[type]; - }else { - propTypeToReturn = React.PropTypes.oneOfType( - type.map( - (type)=>{ - return React.PropTypes[type]; - })); - } - //Mandatory case - if(isRequired){ - propTypeToReturn = propTypeToReturn.isRequired; - } - return propTypeToReturn; +* Expose a React type validation for the component properties validation. +* @see http://facebook.github.io/react/docs/reusable-components.html +* @param {string} type - String or array of the types to use. +* @param {boolean} isRequired - Defines if the props is mandatory. +* @return {object} The corresponding react type. +*/ +module.exports = function types(type, isRequired){ + const isStringType = isString(type); + if(!isStringType && !isArray(type)){ + throw new Error('The type should be a string or an array'); + } + //Container for the propTypes. + let propTypeToReturn; + //Array case. + if(isStringType){ + propTypeToReturn = React.PropTypes[type]; + }else { + propTypeToReturn = React.PropTypes.oneOfType( + type.map( + (t)=>{ + return React.PropTypes[t]; + })); + } + //Mandatory case + if(isRequired){ + propTypeToReturn = propTypeToReturn.isRequired; + } + return propTypeToReturn; }; From d2e3a5a485c6ffb09d5e732ff8eadc8f6284e6fb Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Fri, 21 Aug 2015 23:00:31 +0200 Subject: [PATCH 08/24] [eslint] clean definition/domain --- src/definition/domain/container.js | 87 +++++++++++++++--------------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/src/definition/domain/container.js b/src/definition/domain/container.js index f13b89f..97785ab 100644 --- a/src/definition/domain/container.js +++ b/src/definition/domain/container.js @@ -1,69 +1,68 @@ -"use strict"; - //Dependencies. -var Immutable = require('immutable'); -var isObject = require('lodash/lang/isObject'); -var isString = require('lodash/lang/isString'); -var InvalidException = Error; -var checkIsString = require('../../util/string/check'); -var checkIsObject = require('../../util/object/check'); +const Immutable = require('immutable'); +const isObject = require('lodash/lang/isObject'); +const isString = require('lodash/lang/isString'); +const InvalidException = Error; +const checkIsString = require('../../util/string/check'); +const checkIsObject = require('../../util/object/check'); /** - * Container for the application domains. - * @type {object} - */ +* Container for the application domains. +* @type {object} +*/ let domainsMap = Immutable.Map({}); /** - * Get all domains in a JS Structure. + * Get all domains in a js object. + * @return {object} - All domains. */ function getDomains(){ - return domainsMap.toJS(); + return domainsMap.toJS(); } /** - * Set new domains. - * @param {object} newDomains - New domains to set. - */ +* Set new domains. +* @param {object} newDomains - New domains to set. +* à +*/ function setDomains(newDomains){ - if(!isObject(newDomains)){ - throw new InvalidException('newDomains should be an object', newDomains); - } - domainsMap = domainsMap.merge(newDomains); + if(!isObject(newDomains)){ + throw new InvalidException('newDomains should be an object', newDomains); + } + domainsMap = domainsMap.merge(newDomains); } /** - * Set a domain. - * @param {object} domain - Object structure of the domain. - */ +* Set a domain. +* @param {object} domain - Object structure of the domain. +*/ function setDomain(domain){ - checkIsObject('domain', domain); - checkIsString('doamin.name', domain.name); - //test domain, domain.name - domainsMap = domainsMap.set(domain.name, domain); + checkIsObject('domain', domain); + checkIsString('doamin.name', domain.name); + //test domain, domain.name + domainsMap = domainsMap.set(domain.name, domain); } /** - * Get a domain given a name. - * @param {string} domainName - name of the domain. - */ +* Get a domain given a name. +* @param {string} domainName - name of the domain. +* @return {object} - The domain object. +*/ function getDomain(domainName){ - if(!isString(domainName)){ - throw new InvalidException('domaiName should extists and be a string', domainName); - } - if(!domainsMap.has(domainName)){ - console.warn(`You are trying to access a non existing domain: ${domainName}`); - return Immutable.Map({}); - } - return domainsMap.get(domainName); + if(!isString(domainName)){ + throw new InvalidException('domaiName should extists and be a string', domainName); + } + if(!domainsMap.has(domainName)){ + console.warn(`You are trying to access a non existing domain: ${domainName}`); + return Immutable.Map({}); + } + return domainsMap.get(domainName); } - - module.exports = { - getAll: getDomains, - setAll: setDomains, - set: setDomain, - get: getDomain + getAll: getDomains, + setAll: setDomains, + set: setDomain, + get: getDomain }; From 1ba01c40812ad8e06ef8780c64853478787336f9 Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Fri, 21 Aug 2015 23:07:17 +0200 Subject: [PATCH 09/24] [eslint] clean definition/entity/builder --- src/definition/entity/builder.js | 106 ++++++++++++++++--------------- 1 file changed, 56 insertions(+), 50 deletions(-) diff --git a/src/definition/entity/builder.js b/src/definition/entity/builder.js index db48efe..b3ba9e2 100644 --- a/src/definition/entity/builder.js +++ b/src/definition/entity/builder.js @@ -1,15 +1,15 @@ const Immutable = require('immutable'); -let checkIsString = require('../../util/string/check'); -let checkIsObject = require('../../util/object/check'); -let checkIsNotNull = require('../../util/object/checkIsNotNull'); -const SEPARATOR = "."; +const checkIsString = require('../../util/string/check'); +const checkIsObject = require('../../util/object/check'); +const checkIsNotNull = require('../../util/object/checkIsNotNull'); +const SEPARATOR = '.'; /** - * Pointer to the domain contaier. - * @type {Object} - */ -let domainContainer = require('../domain/container'); -let entityContainer = require('./container'); +* Pointer to the domain contaier. +* @type {Object} +*/ +const domainContainer = require('../domain/container'); +const entityContainer = require('./container'); let computedEntityContainer = Immutable.Map({}); /* @@ -23,65 +23,71 @@ isValidationOff label required domain - */ - -//Interface -// -// +*/ +/** + * Build all entity information from entity name. + * @param {string} entityName - The entity name. + */ function _buildEntityInformation(entityName) { - let entityDomainInfos = entityContainer.getEntityConfiguration(entityName); - checkIsNotNull('entityDomainInfos', entityDomainInfos); - let container = {}; - //Populate the domain values i - for (let key in entityDomainInfos) { - container[key] = _buildFieldInformation(`${entityName}${SEPARATOR}${key}`); - } - //Update the computed information map. - computedEntityContainer = computedEntityContainer.set(entityName, Immutable.Map(container)); + const entityDomainInfos = entityContainer.getEntityConfiguration(entityName); + checkIsNotNull('entityDomainInfos', entityDomainInfos); + let container = {}; + //Populate the domain values i + for (let key in entityDomainInfos) { + container[key] = _buildFieldInformation(`${entityName}${SEPARATOR}${key}`); + } + //Update the computed information map. + computedEntityContainer = computedEntityContainer.set(entityName, Immutable.Map(container)); } - +/** + * Build the field informations. + * @param {string} fieldPath - The field path. + * @return {Immutable.Map} - The immutable field description. + */ function _buildFieldInformation(fieldPath) { - let fieldConf = entityContainer.getFieldConfiguration(fieldPath); - let immutableFieldConf = Immutable.Map(fieldConf); + const fieldConf = entityContainer.getFieldConfiguration(fieldPath); + const immutableFieldConf = Immutable.Map(fieldConf); //Maybe add a domain check existance let {domain} = fieldConf; return domainContainer.get(domain).mergeDeep(immutableFieldConf); } /** - * Get the entity information from the entity name and given the extended informations. - * @param {string} entityName - The name of the entity. - * @param {object} complementaryInformation - Additional . - */ +* Get the entity information from the entity name and given the extended informations. +* @param {string} entityName - The name of the entity. +* @param {object} complementaryInformation - Additional information on the entity. +* @return {object} - The entity informations from the entity name. +*/ function getEntityInformations(entityName, complementaryInformation) { - checkIsString("entityName", entityName); - checkIsObject("complementaryInformation", complementaryInformation); - let key = entityName.split(SEPARATOR); - if (!computedEntityContainer.hasIn(key)) { - _buildEntityInformation(entityName); - } - return computedEntityContainer.get(entityName).mergeDeep(complementaryInformation).toJS(); + checkIsString('entityName', entityName); + checkIsObject('complementaryInformation', complementaryInformation); + const key = entityName.split(SEPARATOR); + if (!computedEntityContainer.hasIn(key)) { + _buildEntityInformation(entityName); + } + return computedEntityContainer.get(entityName).mergeDeep(complementaryInformation).toJS(); } /** - * Get the field informations. - * @param {string} fieldName - name or path of the field. - * @param {object} complementaryInformation - Additional informations to extend the domain informations. - */ +* Get the field informations. +* @param {string} fieldName - name or path of the field. +* @param {object} complementaryInformation - Additional informations to extend the domain informations. +* @return {object} - The builded field informations. +*/ function getFieldInformations(fieldName, complementaryInformation) { - checkIsString("fieldName", fieldName); - checkIsObject("complementaryInformation", complementaryInformation); - let fieldPath = fieldName.split(SEPARATOR); - if (computedEntityContainer.hasIn(fieldPath)) { - return computedEntityContainer.getIn(fieldPath).toJS(); - } - return _buildFieldInformation(fieldPath).mergeDeep(complementaryInformation).toJS(); + checkIsString('fieldName', fieldName); + checkIsObject('complementaryInformation', complementaryInformation); + const fieldPath = fieldName.split(SEPARATOR); + if (computedEntityContainer.hasIn(fieldPath)) { + return computedEntityContainer.getIn(fieldPath).toJS(); + } + return _buildFieldInformation(fieldPath).mergeDeep(complementaryInformation).toJS(); } module.exports = { - getEntityInformations: getEntityInformations, - getFieldInformations: getFieldInformations + getEntityInformations: getEntityInformations, + getFieldInformations: getFieldInformations }; From eacd5607a81de0199757de134a97c7e9c56aa97a Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Fri, 21 Aug 2015 23:14:26 +0200 Subject: [PATCH 10/24] [eslint] clean definition/entity/contrainer --- src/definition/entity/container.js | 108 +++++++++++++++-------------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/src/definition/entity/container.js b/src/definition/entity/container.js index c54cef6..722c77f 100644 --- a/src/definition/entity/container.js +++ b/src/definition/entity/container.js @@ -1,78 +1,80 @@ -"use strict"; - //Dependencies. -var Immutable = require('immutable'); -var InvalidException = Error; -var checkIsString = require('../../util/string/check'); -var checkIsObject = require('../../util/object/check'); +const Immutable = require('immutable'); +const checkIsString = require('../../util/string/check'); +const checkIsObject = require('../../util/object/check'); /** - * Separator for the configuration - * @type {String} - */ -const SEPARATOR = "."; +* Separator for the configuration +* @type {String} +*/ +const SEPARATOR = '.'; /** - * Container for the application entities. - * @type {object} - */ -var entitiesMap = Immutable.Map({}); +* Container for the application entities. +* @type {object} +*/ +let entitiesMap = Immutable.Map({}); /** - * Get all entityDefinition in a JS Structure. - * @param {object} extendedEntityConfiguration - The object to extend the config. - */ +* Get all entityDefinition in a JS Structure. +* @param {string} - The node path (with .). +* @param {object} extendedEntityConfiguration - The object to extend the config. +* @return {object} - The entity configuration from a given path. +*/ function getEntityConfiguration(nodePath, extendedEntityConfiguration){ - //If a node is specified get the direct sub conf. - if(nodePath){ - return _getNode(nodePath, extendedEntityConfiguration).toJS(); - } - return entitiesMap.toJS(); + //If a node is specified get the direct sub conf. + if(nodePath){ + return _getNode(nodePath, extendedEntityConfiguration).toJS(); + } + return entitiesMap.toJS(); } /** - * Set new entities in the map or extend existing one. - * @param {object} newEntities - new entities description - */ +* Set new entities in the map or extend existing one. +* @param {object} newEntities - new entities description +*/ function setEntityConfiguration(newEntities){ - checkIsObject('newEntities', newEntities); - entitiesMap = entitiesMap.mergeDeep(newEntities); + checkIsObject('newEntities', newEntities); + entitiesMap = entitiesMap.mergeDeep(newEntities); } /** - * Get a node configuration given a node path "obj.prop.subProp". - * @param {string} nodePath - The node path you want to get. - * @param {object} extendedConfiguration - The object to extend the config. - */ +* Get a node configuration given a node path "obj.prop.subProp". +* @param {string} nodePath - The node path you want to get. +* @param {object} extendedConfiguration - The object to extend the config. +* @return {object} - The node configuration. +*/ function _getNode(nodePath, extendedConfiguration){ - checkIsString("nodePath",nodePath); - if(!entitiesMap.hasIn(nodePath.split(SEPARATOR))){ - console.warn(` - It seems the definition your are trying to use does not exists in the entity definitions of your project. - The definition you want is ${nodePath} and the definition map is: - `, entitiesMap.toJS()); - throw new Error('Wrong definition path given, see waning for more details'); - } - var conf = entitiesMap.getIn(nodePath.split(SEPARATOR)); - if(extendedConfiguration){ - checkIsObject(extendedConfiguration); - conf = conf.mergeDeep(extendedConfiguration); - } - return conf; + checkIsString('nodePath', nodePath); + if(!entitiesMap.hasIn(nodePath.split(SEPARATOR))){ + console.warn(` + It seems the definition your are trying to use does not exists in the entity definitions of your project. + The definition you want is ${nodePath} and the definition map is: + `, entitiesMap.toJS() + ); + throw new Error('Wrong definition path given, see waning for more details'); + } + let conf = entitiesMap.getIn(nodePath.split(SEPARATOR)); + if(extendedConfiguration){ + checkIsObject(extendedConfiguration); + conf = conf.mergeDeep(extendedConfiguration); + } + return conf; } /** - * Get a field configuration given a path. - * @param {string} fieldPath - The field path in the map. - * @param {object} customFieldConf - The object to extend the config. - */ +* Get a field configuration given a path. +* @param {string} fieldPath - The field path in the map. +* @param {object} customFieldConf - The object to extend the config. +* @return {object} - The field configuration. +*/ function getFieldConfiguration(fieldPath, customFieldConf){ - return _getNode(fieldPath, customFieldConf).toJS(); + return _getNode(fieldPath, customFieldConf).toJS(); } module.exports = { - getEntityConfiguration: getEntityConfiguration, - setEntityConfiguration: setEntityConfiguration, - getFieldConfiguration: getFieldConfiguration + getEntityConfiguration: getEntityConfiguration, + setEntityConfiguration: setEntityConfiguration, + getFieldConfiguration: getFieldConfiguration }; From cb70e429bf5f635de2c1f282d7fd49f6097af18c Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Fri, 21 Aug 2015 23:16:42 +0200 Subject: [PATCH 11/24] [eslint] clean definition/entity/formatter --- src/definition/formatter/number.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/definition/formatter/number.js b/src/definition/formatter/number.js index fdd64d8..db973c1 100644 --- a/src/definition/formatter/number.js +++ b/src/definition/formatter/number.js @@ -1,8 +1,14 @@ -let numeral = require('numeral'); +const numeral = require('numeral'); const DEFAULT_FORMAT = '0,0'; module.exports = { + /** + * Format a number using a given format. + * @param {number} number - The number to format. + * @param {string} format - The format to transform. + * @return {string} - The formated number. + */ format(number, format) { format = format || DEFAULT_FORMAT; return numeral(number).format(format); From 615089e64deb0cffdf324154920b0d373c0b55ad Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Fri, 21 Aug 2015 23:17:00 +0200 Subject: [PATCH 12/24] [eslint] clean definition/entity/formatter/index --- src/definition/formatter/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/definition/formatter/index.js b/src/definition/formatter/index.js index cd5f822..de67605 100644 --- a/src/definition/formatter/index.js +++ b/src/definition/formatter/index.js @@ -1,3 +1,3 @@ module.exports = { number: require('./number') -}; \ No newline at end of file +}; From 9d29a1d69a695f84af530a0593fc4448e9318c93 Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Fri, 21 Aug 2015 23:19:29 +0200 Subject: [PATCH 13/24] [eslint] clean definition/entity/validator --- src/definition/validator/date.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/definition/validator/date.js b/src/definition/validator/date.js index 22ce822..3265a0c 100644 --- a/src/definition/validator/date.js +++ b/src/definition/validator/date.js @@ -1,8 +1,13 @@ - +/** +* Validate a date. +* @param {string | date} dateToValidate - The date to validate. +* @param {object} options - The validator options. +* @return {string} - The formated date. +*/ module.exports = function dateValidation(dateToValidate, options) { - var moment = require('moment'); - if(!moment){ - console.warn('Moment library is not a part of your project, please download it : http://momentjs.com/'); - } - return moment(dateToValidate).isValid(); + const moment = require('moment'); + if(!moment){ + console.warn('Moment library is not a part of your project, please download it : http://momentjs.com/'); + } + return moment(dateToValidate, options).isValid(); }; From e8da380cd28a9323f8a9dce6cfdc2c1b61d28700 Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Fri, 21 Aug 2015 23:21:42 +0200 Subject: [PATCH 14/24] [eslint] clean definition/entity/validator/date,email --- src/definition/validator/date.js | 2 +- src/definition/validator/email.js | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/definition/validator/date.js b/src/definition/validator/date.js index 3265a0c..2b7d781 100644 --- a/src/definition/validator/date.js +++ b/src/definition/validator/date.js @@ -2,7 +2,7 @@ * Validate a date. * @param {string | date} dateToValidate - The date to validate. * @param {object} options - The validator options. -* @return {string} - The formated date. +* @return {boolean} - True if the date is valide , false otherwise. */ module.exports = function dateValidation(dateToValidate, options) { const moment = require('moment'); diff --git a/src/definition/validator/email.js b/src/definition/validator/email.js index 4b65d81..523654d 100644 --- a/src/definition/validator/email.js +++ b/src/definition/validator/email.js @@ -1,7 +1,10 @@ const EMAIL_REGEX = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; -//Function to test an email. -module.exports = function emailValidation(emailToValidate, options) { - options = options || {}; - return EMAIL_REGEX.test(emailToValidate); +/** + * Email validator using a Regex. + * @param {string} emailToValidate - The email to validate. + * @return {boolean} - True if the email is valide , false otherwise. + */ +module.exports = function emailValidation(emailToValidate) { + return EMAIL_REGEX.test(emailToValidate); }; From 94584476a41b4524d609a7e5fcb792cfcf39dac3 Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Fri, 21 Aug 2015 23:22:11 +0200 Subject: [PATCH 15/24] [eslint] clean definition/entity/validator/number --- src/definition/validator/number.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/definition/validator/number.js b/src/definition/validator/number.js index 2228b9c..6b1e8e8 100644 --- a/src/definition/validator/number.js +++ b/src/definition/validator/number.js @@ -1,4 +1,3 @@ -const NUMBER_REGEX = /^-?\d+(?:\.d*)?(?:e[+\-]?\d+)?$/i; let {isUndefined, isNull, isNaN, isNumber} = require('lodash/lang'); /* Function to validate that an input is a number. From ca7fa6563db381bdfdaa7bd36d2aef8738f33a2d Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Fri, 21 Aug 2015 23:25:19 +0200 Subject: [PATCH 16/24] [eslint] clean definition/entity/validator/string --- src/definition/validator/string-length.js | 26 +++++++++++++---------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/definition/validator/string-length.js b/src/definition/validator/string-length.js index 8320a61..60dade3 100644 --- a/src/definition/validator/string-length.js +++ b/src/definition/validator/string-length.js @@ -1,12 +1,16 @@ -//Function to test the length of a string. -module.exports = function stringLength(stringToTest, options) { - if ('string' !== typeof stringToTest) { - return false; - } - options = options || {}; - //console.log(options); - options.minLength = options.minLength || 0; - var isMinLength = options.minLength !== undefined ? stringToTest.length >= options.minLength : true; - var isMaxLength = options.maxLength !== undefined ? stringToTest.length <= options.maxLength : true; - return isMinLength && isMaxLength; +let {isString} = require('lodash/lang'); +/** + * Validate a string given options. + * @param {string} stringToTest - The string to test. + * @param {object} options - Validators options, supports minLength and maxLength both optionals. + * @return {boolean} - True if the string is valid , false otherwise. + */ +module.exports = function stringLength(stringToTest, options = {}) { + if (!isString(stringToTest)) { + return false; + } + options.minLength = options.minLength || 0; + const isMinLength = options.minLength !== undefined ? stringToTest.length >= options.minLength : true; + const isMaxLength = options.maxLength !== undefined ? stringToTest.length <= options.maxLength : true; + return isMinLength && isMaxLength; }; From 0daf0f0ef5c30e462073a2f763d21ce285f22e84 Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Fri, 21 Aug 2015 23:43:54 +0200 Subject: [PATCH 17/24] [eslint] clean definition/entity/validator/validate --- src/definition/validator/validate.js | 179 +++++++++++++++------------ 1 file changed, 98 insertions(+), 81 deletions(-) diff --git a/src/definition/validator/validate.js b/src/definition/validator/validate.js index 833fbab..1d4c67b 100644 --- a/src/definition/validator/validate.js +++ b/src/definition/validator/validate.js @@ -1,91 +1,108 @@ //Dependency -let DependencyException = require("../../exception").DependencyException; -let assign = require('object-assign'); - +const DependencyException = require('../../exception').DependencyException; +const assign = require('object-assign'); //Focus validators -let emailValidation = require('./email'); -let numberValidation = require('./number'); -let stringLength = require('./string-length'); -let dateValidation = require('./date'); - -//Validate a property, a property shoul be as follow: `{name: "field_name",value: "field_value", validators: [{...}] }` -var validate = function validate(property, validators) { - //console.log("validate", property, validators); - var errors, res, validator, _i, _len; - errors = []; - if (validators) { - for (_i = 0, _len = validators.length; _i < _len; _i++) { - validator = validators[_i]; - res = validateProperty(property, validator); - if (res !== null && res !== undefined) { - errors.push(res); - } +const emailValidation = require('./email'); +const numberValidation = require('./number'); +const stringLength = require('./string-length'); +const dateValidation = require('./date'); +const {isNull, isUndefined} = require('lodash/lang'); +/** +* Validae a property given validators. +* @param {object} property - Property to validate which should be as follows: `{name: "field_name",value: "field_value", validators: [{...}] }`. +* @param {array} validators - The validators to apply on the property. +* @return {object} - The validation status. +*/ +function validate(property, validators) { + //console.log("validate", property, validators); + let errors = [], res, validator; + if (validators) { + for (let i = 0, _len = validators.length; i < _len; i++) { + validator = validators[i]; + res = validateProperty(property, validator); + if (!isNull(res) && !isUndefined(res)) { + errors.push(res); + } + } } - } - //Check what's the good type to return. - return { - name: property.name, - value: property.value, - isValid: errors.length === 0, - errors: errors - }; -}; + //Check what's the good type to return. + return { + name: property.name, + value: property.value, + isValid: 0 === errors.length, + errors: errors + }; +} +/** +* Validate a property. +* @param {object} property - The property to validate. +* @param {function} validator - The validator to apply. +* @return {object} - The property validation status. +*/ function validateProperty(property, validator) { - var isValid; - if (!validator) { - return void 0; - } - if (!property) { - return void 0; - } - isValid = (function () { - switch (validator.type) { - case "required": - var prevalidString = property.value === "" ? false : true; - var prevalidDate = true; - return validator.value === true ? (property.value !== null && property.value !== undefined && prevalidString && prevalidDate) : true; - case "regex": - if (property.value === undefined || property.value === null) { - return true; - } - return validator.value.test(property.value); - case "email": - if (property.value === undefined || property.value === null) { - return true; - } - return emailValidation(property.value, validator.options); - case "number": - return numberValidation(property.value, validator.options); - case "string": - var stringToValidate = property.value || ""; - return stringLength(stringToValidate, validator.options); - case "date": - return dateValidation(property.value, validator.options); - case "function": - return validator.value(property.value, validator.options); - default: + let isValid; + if (!validator) { return void 0; } - })(); - if (isValid === undefined || isValid === null) { - console.warn('The validator of type: ' + validator.type + ' is not defined'); //Todo: call the logger. - } else if (isValid === false) { - - //Add the name of the property. - return getErrorLalel(validator.type, property.modelName + '.' + property.name, validator.options); //"The property " + property.name + " is invalid."; - } -}; - -function getErrorLalel(type, fieldName, options) { - options = options || {}; - let i18n = require('i18n'); - if (!i18n) { - throw new DependencyException("Dependency not resolved: i18n.js"); - } - var translationKey = options.translationKey ? options.translationKey : "domain.validation." + type; - var opts = assign({fieldName: i18n.t(fieldName)}, options); - return i18n.t(translationKey, opts); + if (!property) { + return void 0; + } + const value = {property}; + const {options} = validator; + const isValueNullOrUndefined = isNull(value) || isUndefined(value ); + isValid = (()=>{ + switch (validator.type) { + case 'required': + const prevalidString = '' === property.value ? false : true; + const prevalidDate = true; + return true === validator.value ? (!isNull(property.value) && !isUndefined(property.value ) && prevalidString && prevalidDate) : true; + case 'regex': + if (isValueNullOrUndefined) { + return true; + } + return validator.value.test(property.value); + case 'email': + if (isValueNullOrUndefined) { + return true; + } + return emailValidation(value, options); + case 'number': + return numberValidation(value, options); + case 'string': + const stringToValidate = property.value || ''; + return stringLength(stringToValidate, options); + case 'date': + return dateValidation(property.value, options); + case 'function': + return validator.value(property.value, options); + default: + return void 0; + } + })(); + if (isUndefined(isValid) || isNull(isValid)) { + console.warn(`The validator of type: ${validator.tye} is not defined`); + } else if (false === isValid) { + //Add the name of the property. + return getErrorLalel(validator.type, property.modelName + '.' + property.name, options); //"The property " + property.name + " is invalid."; + } +} +/** + * Get the error label from a type and a field name. + * @param {string} type - The type name. + * @param {string} fieldName - The field name. + * @param {object} options - The options to put such as the translationKey which could be defined in the domain. + * @return {string} The formatted error. + */ +function getErrorLalel(type, fieldName, options = {}) { + options = options || {}; + const i18n = require('i18n'); + if (!i18n) { + throw new DependencyException('Dependency not resolved: i18n.js'); + } + const translationKey = options.translationKey ? options.translationKey : `domain.validation.${type}`; + const opts = assign({fieldName: i18n.t(fieldName)}, options); + return i18n.t(translationKey, opts); } module.exports = validate; From 8eb1a0d33ac4bc5ce54f2c0c7e62da5f3a1ef40a Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Fri, 21 Aug 2015 23:44:21 +0200 Subject: [PATCH 18/24] [router] rename clearCartridge into clearHeader --- src/router/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/router/index.js b/src/router/index.js index c86c99f..f315130 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -11,7 +11,7 @@ var isFunction = require('lodash/lang/isFunction'); */ function _beforeRouting(newRoute){ //application.changeRoute(newRoute); - application.clearCartridge(); + application.clearHeader(); } module.exports = Backbone.Router.extend({ noRoleRoute: 'home', From b1cbbd2a7133098483579393ffa32ce1340979e3 Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Sat, 22 Aug 2015 22:11:23 +0200 Subject: [PATCH 19/24] [eslint] clean check domain. --- _book | 1 + src/definition/check-domains.js | 43 ++++++++++++++++----------------- 2 files changed, 22 insertions(+), 22 deletions(-) create mode 160000 _book diff --git a/_book b/_book new file mode 160000 index 0000000..d1fd69e --- /dev/null +++ b/_book @@ -0,0 +1 @@ +Subproject commit d1fd69ea0a66a648737d31b4bdae72168fd63ccc diff --git a/src/definition/check-domains.js b/src/definition/check-domains.js index 4ae00d1..9ac8dc1 100644 --- a/src/definition/check-domains.js +++ b/src/definition/check-domains.js @@ -1,26 +1,25 @@ -let keys = require('lodash/object/keys'); +const keys = require('lodash/object/keys'); let {intersection, uniq, difference} = require('lodash/array'); -module.exports = (entityDef, domains)=>{ - domains = Object.keys(domains); - let arr = []; - for (let node in entityDef) { - for (let sub in entityDef[node]) { - arr.push(entityDef[node][sub].domain); +module.exports = function checkDomain(entityDef, domains){ + domains = keys(domains); + let arr = []; + for (let node in entityDef) { + for (let sub in entityDef[node]) { + arr.push(entityDef[node][sub].domain); + } } - } - let appDomains = uniq(arr); - console.info('########################## DOMAINS ##############################'); - console.info('Entity definitions domains: ', appDomains); - console.info('Domains with a definition',domains); - let missingDomains = difference(appDomains, intersection(appDomains,domains)); - if(missingDomains.length > 0){ - console.warn('Missing domain\'s definition', missingDomains); - } - let useLessDomains =difference(domains, _.intersection(appDomains,domains)); - if(useLessDomains > 0){ - console.warn('Useless domain\'s definition',useLessDomains); - } - - console.info('####################################################################'); + const appDomains = uniq(arr); + console.info('########################## DOMAINS ##############################'); + console.info('Entity definitions domains: ', appDomains); + console.info('Domains with a definition', domains); + const missingDomains = difference(appDomains, intersection(appDomains, domains)); + if(0 < missingDomains.length){ + console.warn('Missing domain\'s definition', missingDomains); + } + const useLessDomains = difference(domains, intersection(appDomains, domains)); + if(0 < useLessDomains){ + console.warn('Useless domain definition', useLessDomains); + } + console.info('####################################################################'); } From e75e818eb8c993ea42b3f07864d3b6db33ecd06e Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Sat, 22 Aug 2015 22:27:50 +0200 Subject: [PATCH 20/24] [eslint][dispatcher] --- src/dispatcher/Dispatcher.js | 7 ---- src/dispatcher/index.js | 62 +++++++++++++++++------------------- 2 files changed, 30 insertions(+), 39 deletions(-) delete mode 100644 src/dispatcher/Dispatcher.js diff --git a/src/dispatcher/Dispatcher.js b/src/dispatcher/Dispatcher.js deleted file mode 100644 index de402f9..0000000 --- a/src/dispatcher/Dispatcher.js +++ /dev/null @@ -1,7 +0,0 @@ -//By default use the facebook flux dispatcher. -var Dispatcher = require('flux').Dispatcher; -/** - * Core Dispatcher. - * @type {Object} - */ -module.exports = Dispatcher; diff --git a/src/dispatcher/index.js b/src/dispatcher/index.js index a1ba824..909dcaa 100644 --- a/src/dispatcher/index.js +++ b/src/dispatcher/index.js @@ -1,35 +1,33 @@ -var Dispatcher = require('./Dispatcher'); -var assign = require('object-assign'); +const Dispatcher = require('flux').Dispatcher; +const assign = require('object-assign'); -var AppDispaytcher = assign(new Dispatcher(), { - - /** - * @param {object} action The details of the action, including the action's - * type and additional data coming from the server. - */ - handleServerAction: function(action) { - var payload = { - source: "SERVER_ACTION", - action: action - }; - this.dispatch(payload); - }, - - /** - * @param {object} action The details of the action, including the action's - * type and additional data coming from the view. - */ - handleViewAction: function(action) { - var payload = { - source: "VIEW_ACTION", - action: action - }; - this.dispatch(payload); - } +/** +* Application dispatcher. +* @type {Object} +*/ +const AppDispatcher = assign(new Dispatcher(), { + /** + * @param {object} action The details of the action, including the action's + * type and additional data coming from the server. + */ + handleServerAction(action) { + const payload = { + source: 'SERVER_ACTION', + action: action + }; + this.dispatch(payload); + }, + /** + * @param {object} action The details of the action, including the action's + * type and additional data coming from the view. + */ + handleViewAction(action) { + const payload = { + source: 'VIEW_ACTION', + action: action + }; + this.dispatch(payload); + } }); -/** - * Application dispatcher. - * @type {Object} - */ -module.exports = AppDispaytcher; +module.exports = AppDispatcher; From 0f5027790469f32dd39e3b09a5a20274ca14d1e4 Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Sat, 22 Aug 2015 22:28:36 +0200 Subject: [PATCH 21/24] [eslint][definition] --- src/definition/check-domains.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/definition/check-domains.js b/src/definition/check-domains.js index 9ac8dc1..ba1687a 100644 --- a/src/definition/check-domains.js +++ b/src/definition/check-domains.js @@ -22,4 +22,4 @@ module.exports = function checkDomain(entityDef, domains){ console.warn('Useless domain definition', useLessDomains); } console.info('####################################################################'); -} +}; From 24f022afde2da07dc9dac4093b1df59c35f87be6 Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Mon, 24 Aug 2015 08:59:07 +0200 Subject: [PATCH 22/24] [action-builder] --- src/exception/ArgumentInvalidException.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/exception/ArgumentInvalidException.js b/src/exception/ArgumentInvalidException.js index 6b57aaa..9e28a5f 100644 --- a/src/exception/ArgumentInvalidException.js +++ b/src/exception/ArgumentInvalidException.js @@ -1,15 +1,15 @@ -var CustomException = require('./CustomException'); -/** - * Class standing for the NotImplemented exceptions. - */ +const CustomException = require('./CustomException'); +/** +* Class standing for the NotImplemented exceptions. +*/ class ArgumentInvalidException extends CustomException { /** - * Exception constructor.. - * @param messgae {string} - Exception message. - * @param options {object} - Object to add to the exception. - */ + * Exception constructor.. + * @param messgae {string} - Exception message. + * @param options {object} - Object to add to the exception. + */ constructor(message, options) { - super("ArgumentInvalidException", message, options); + super('ArgumentInvalidException', message, options); } } From 100f41812cef29f2b35b5d36d8945701e8c6b4bf Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Mon, 24 Aug 2015 09:10:21 +0200 Subject: [PATCH 23/24] [exception] rename --- ...{ArgumentInvalidException.js => argument-invalid-exception.js} | 0 .../{ArgumentNullException.js => argument-null-exception.js} | 0 src/exception/{CustomException.js => custom-exception.js} | 0 src/exception/{DependencyException.js => dependency-exception.js} | 0 src/exception/{FocusException.js => focus-exception.js} | 0 .../{NotImplementedException.js => not-implemented-exception.js} | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename src/exception/{ArgumentInvalidException.js => argument-invalid-exception.js} (100%) rename src/exception/{ArgumentNullException.js => argument-null-exception.js} (100%) rename src/exception/{CustomException.js => custom-exception.js} (100%) rename src/exception/{DependencyException.js => dependency-exception.js} (100%) rename src/exception/{FocusException.js => focus-exception.js} (100%) rename src/exception/{NotImplementedException.js => not-implemented-exception.js} (100%) diff --git a/src/exception/ArgumentInvalidException.js b/src/exception/argument-invalid-exception.js similarity index 100% rename from src/exception/ArgumentInvalidException.js rename to src/exception/argument-invalid-exception.js diff --git a/src/exception/ArgumentNullException.js b/src/exception/argument-null-exception.js similarity index 100% rename from src/exception/ArgumentNullException.js rename to src/exception/argument-null-exception.js diff --git a/src/exception/CustomException.js b/src/exception/custom-exception.js similarity index 100% rename from src/exception/CustomException.js rename to src/exception/custom-exception.js diff --git a/src/exception/DependencyException.js b/src/exception/dependency-exception.js similarity index 100% rename from src/exception/DependencyException.js rename to src/exception/dependency-exception.js diff --git a/src/exception/FocusException.js b/src/exception/focus-exception.js similarity index 100% rename from src/exception/FocusException.js rename to src/exception/focus-exception.js diff --git a/src/exception/NotImplementedException.js b/src/exception/not-implemented-exception.js similarity index 100% rename from src/exception/NotImplementedException.js rename to src/exception/not-implemented-exception.js From 585f89f97452dd8b8b64fb0540c4932952ab9065 Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Mon, 24 Aug 2015 09:33:53 +0200 Subject: [PATCH 24/24] [exception] rename --- .../domain/__tests__/container-test.js | 2 +- src/exception/argument-invalid-exception.js | 8 +-- src/exception/argument-null-exception.js | 22 +++---- src/exception/custom-exception.js | 64 ++++++++++--------- src/exception/dependency-exception.js | 22 +++---- src/exception/focus-exception.js | 16 ++--- src/exception/index.js | 12 ++-- src/exception/not-implemented-exception.js | 22 +++---- src/router/index.js | 2 +- src/util/object/__tests__/check-test.js | 2 +- src/util/object/check.js | 2 +- src/util/object/checkIsNotNull.js | 2 +- src/util/string/check.js | 2 +- test/dontMock.js | 4 +- 14 files changed, 92 insertions(+), 90 deletions(-) diff --git a/src/definition/domain/__tests__/container-test.js b/src/definition/domain/__tests__/container-test.js index 44fb2fc..0875888 100644 --- a/src/definition/domain/__tests__/container-test.js +++ b/src/definition/domain/__tests__/container-test.js @@ -2,7 +2,7 @@ // __tests__/container-test.js jest.dontMock('../container'); require('../../../test/dontMock'); -var ArgumentInvalidException = require('../../../exception/ArgumentInvalidException'); +var ArgumentInvalidException = require('../../../exception/argument-invalid-exception'); describe('### container', function() { diff --git a/src/exception/argument-invalid-exception.js b/src/exception/argument-invalid-exception.js index 9e28a5f..6e4224c 100644 --- a/src/exception/argument-invalid-exception.js +++ b/src/exception/argument-invalid-exception.js @@ -1,12 +1,12 @@ -const CustomException = require('./CustomException'); +const CustomException = require('./custom-exception'); /** * Class standing for the NotImplemented exceptions. */ class ArgumentInvalidException extends CustomException { /** - * Exception constructor.. - * @param messgae {string} - Exception message. - * @param options {object} - Object to add to the exception. + * Exception constructor. + * @param {string} message - Exception message. + * @param {object} options - Object to add to the exception. */ constructor(message, options) { super('ArgumentInvalidException', message, options); diff --git a/src/exception/argument-null-exception.js b/src/exception/argument-null-exception.js index a58d6b5..77b2966 100644 --- a/src/exception/argument-null-exception.js +++ b/src/exception/argument-null-exception.js @@ -1,16 +1,16 @@ -var CustomException = require('./CustomException'); +const CustomException = require('./custom-exception'); /** - * Class standing for the NotImplemented exceptions. - */ +* Class standing for the NotImplemented exceptions. +*/ class ArgumentNullException extends CustomException{ - /** - * Exception constructor.. - * @param messgae {string} - Exception message. - * @param options {object} - Object to add to the exception. - */ - constructor(message, options){ - super("ArgumentNullException", message, options); - } + /** + * Exception constructor.. + * @param message {string} - Exception message. + * @param options {object} - Object to add to the exception. + */ + constructor(message, options){ + super('ArgumentNullException', message, options); + } } module.exports = ArgumentNullException; diff --git a/src/exception/custom-exception.js b/src/exception/custom-exception.js index cfee057..49f1b2c 100644 --- a/src/exception/custom-exception.js +++ b/src/exception/custom-exception.js @@ -1,37 +1,39 @@ /** - * Classe standing for custom exception. - * @see https://gist.github.com/daliwali/09ca19032ab192524dc6 - */ +* Classe standing for custom exception. +* @see https://gist.github.com/daliwali/09ca19032ab192524dc6 +*/ class CustomException extends Error{ - constructor(name, message, options){ - super(); - if (Error.hasOwnProperty('captureStackTrace')){ - Error.captureStackTrace(this, this.constructor); - } else{ - Object.defineProperty(this, 'stack', { - value: (new Error()).stack - }); + constructor(name, message, options){ + super(); + if (Error.hasOwnProperty('captureStackTrace')){ + Error.captureStackTrace(this, this.constructor); + } else{ + Object.defineProperty(this, 'stack', { + value: (new Error()).stack + }); + } + Object.defineProperty(this, 'message', { + value: message + }); + this.options = options; + } + get name () { + return this.constructor.name; + } + /** + * Log the exception in the js console. + */ + log(){ + console.error('name', this.name, 'message', this.message, 'options', this.options); + } + /** + * Jsonify the exception. + * @return {object} - The json exception. + */ + toJSON(){ + const {name, message, options} = this; + return {name, message, options}; } - Object.defineProperty(this, 'message', { - value: message - }); - this.options = options; - } - get name () { - return this.constructor.name; - } - /** - * Log the exception in the js console. - */ - log(){ - console.error("name", this.name, "message", this.message, "options", this.options); - } - /** - * JSONify the exception. - */ - toJSON(){ - return {"name": this.name, "message": this.message, "options": this.options}; - } } diff --git a/src/exception/dependency-exception.js b/src/exception/dependency-exception.js index 69c5f92..e27f06f 100644 --- a/src/exception/dependency-exception.js +++ b/src/exception/dependency-exception.js @@ -1,16 +1,16 @@ -var CustomException = require('./CustomException'); +const CustomException = require('./custom-exception'); /** - * Class standing for the NotImplemented exceptions. - */ +* Class standing for the NotImplemented exceptions. +*/ class DependencyException extends CustomException{ - /** - * Exception constructor.. - * @param messgae {string} - Exception message. - * @param options {object} - Object to add to the exception. - */ - constructor(message, options){ - super("DependencyException", message, options); - } + /** + * Exception constructor.. + * @param message {string} - Exception message. + * @param options {object} - Object to add to the exception. + */ + constructor(message, options){ + super('DependencyException', message, options); + } } module.exports = DependencyException; diff --git a/src/exception/focus-exception.js b/src/exception/focus-exception.js index ba74de3..ac29681 100644 --- a/src/exception/focus-exception.js +++ b/src/exception/focus-exception.js @@ -1,15 +1,15 @@ -let CustomException = require('./CustomException'); +const CustomException = require('./custom-exception'); /** - * Class standing for the FocusException exceptions. - */ +* Class standing for the FocusException exceptions. +*/ class FocusException extends CustomException { /** - * Exception constructor.. - * @param messgae {string} - Exception message. - * @param options {object} - Object to add to the exception. - */ + * Exception constructor.. + * @param messgae {string} - Exception message. + * @param options {object} - Object to add to the exception. + */ constructor(message, options) { - super("FocusException", message, options); + super('FocusException', message, options); } } diff --git a/src/exception/index.js b/src/exception/index.js index 7f979db..8e5c0f4 100644 --- a/src/exception/index.js +++ b/src/exception/index.js @@ -1,8 +1,8 @@ module.exports = { - ArgumentInvalidException: require('./ArgumentInvalidException'), - ArgumentNullException: require('./ArgumentNullException'), - CustomException: require('./CustomException'), - DependencyException: require('./DependencyException'), - FocusException: require('./FocusException'), - NotImplementedException: require('./NotImplementedException') + ArgumentInvalidException: require('./argument-invalid-exception'), + ArgumentNullException: require('./argument-null-exception'), + CustomException: require('./custom-exception'), + DependencyException: require('./dependency-exception'), + FocusException: require('./focus-exception'), + NotImplementedException: require('./not-implemented-exception') }; diff --git a/src/exception/not-implemented-exception.js b/src/exception/not-implemented-exception.js index 415ffaa..7768a36 100644 --- a/src/exception/not-implemented-exception.js +++ b/src/exception/not-implemented-exception.js @@ -1,16 +1,16 @@ -var CustomException = require('./CustomException'); +const CustomException = require('./custom-exception'); /** - * Class standing for the NotImplemented exceptions. - */ +* Class standing for the NotImplemented exceptions. +*/ class NotImplementedException extends CustomException{ - /** - * Exception constructor.. - * @param messgae {string} - Exception message. - * @param options {object} - Object to add to the exception. - */ - constructor(message, options){ - super("NotImplementedException", message, options); - } + /** + * Exception constructor. + * @param message {string} - Exception message. + * @param options {object} - Object to add to the exception. + */ + constructor(message, options){ + super('NotImplementedException', message, options); + } } module.exports = NotImplementedException; diff --git a/src/router/index.js b/src/router/index.js index f315130..23f3062 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,6 +1,6 @@ var render = require('../application/render'); var Backbone = require('backbone'); -var ArgumentNullException = require('../exception/ArgumentNullException'); +var ArgumentNullException = require('../exception/argument-null-exception'); var message = require('../message'); var userHelper = require('../user'); var dispatcher = require('../dispatcher'); diff --git a/src/util/object/__tests__/check-test.js b/src/util/object/__tests__/check-test.js index 930d567..e253f79 100644 --- a/src/util/object/__tests__/check-test.js +++ b/src/util/object/__tests__/check-test.js @@ -2,7 +2,7 @@ // __tests__/container-test.js jest.dontMock('../check.js'); require('../../../test/dontMock'); -var ArgumentInvalidException = require('../../../exception/ArgumentInvalidException'); +var ArgumentInvalidException = require('../../../exception/argument-invalid-exception'); describe('### object check test', function() { it('The domain', function() { diff --git a/src/util/object/check.js b/src/util/object/check.js index 1a85371..729b3c2 100644 --- a/src/util/object/check.js +++ b/src/util/object/check.js @@ -1,5 +1,5 @@ var ArgumentInvalidException = require( - '../../exception/ArgumentInvalidException'); + '../../exception/argument-invalid-exception'); var isObject = require('lodash/lang/isObject'); /** diff --git a/src/util/object/checkIsNotNull.js b/src/util/object/checkIsNotNull.js index 6d4be8d..cf68a79 100644 --- a/src/util/object/checkIsNotNull.js +++ b/src/util/object/checkIsNotNull.js @@ -1,4 +1,4 @@ -var ArgumentNullException = require('../../exception/ArgumentNullException'); +var ArgumentNullException = require('../../exception/argument-null-exception'); var {isNull, isUndefined} = require('lodash/lang'); /** diff --git a/src/util/string/check.js b/src/util/string/check.js index 43f3b7d..bc2cac5 100644 --- a/src/util/string/check.js +++ b/src/util/string/check.js @@ -1,5 +1,5 @@ var ArgumentInvalidException = require( - '../../exception/ArgumentInvalidException'); + '../../exception/argument-invalid-exception'); var isString = require('lodash/lang/isString'); /** diff --git a/test/dontMock.js b/test/dontMock.js index 0029cc2..f7bb2c2 100644 --- a/test/dontMock.js +++ b/test/dontMock.js @@ -1,8 +1,8 @@ //Exceptions. function exception(){ jest.dontMock('../exception.js'); - jest.dontMock('../exception/ArgumentInvalidException.js'); - jest.dontMock('../exception/ArgumentNullException.js'); + jest.dontMock('../exception/argument-invalid-exception.js'); + jest.dontMock('../exception/argument-null-exception.js'); jest.dontMock('../exception/CustomException.js'); }