From 24a66f8e13fb0a3d9afc356e83de8827d1a5fd05 Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Fri, 1 Mar 2019 23:23:34 +0100 Subject: [PATCH 01/10] rename variable (use full words to be more explicit) --- src/agent/Intentions.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/agent/Intentions.js b/src/agent/Intentions.js index 746158a..0e5efc4 100644 --- a/src/agent/Intentions.js +++ b/src/agent/Intentions.js @@ -2,12 +2,12 @@ * JS-son agent intentions generator * @param {object} beliefs the agent's current beliefs * @param {object} desires the agent's desires (from which the intentions are filtered) - * @param {function} preferenceFunctionGen + * @param {function} preferenceFunctionGenerator * @returns {array} JS-son agent intentions */ -const Intentions = (beliefs, desires, preferenceFunctionGen) => { +const Intentions = (beliefs, desires, preferenceFunctionGenerator) => { const intentions = {} - const intentionKeys = Object.keys(desires).filter(preferenceFunctionGen(beliefs, desires)) + const intentionKeys = Object.keys(desires).filter(preferenceFunctionGenerator(beliefs, desires)) intentionKeys.forEach(intentionKey => (intentions[intentionKey] = desires[intentionKey](beliefs))) return intentions } From 3819cbc8a07f3ef770438b169af3adad0b4cb835 Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Fri, 1 Mar 2019 23:35:21 +0100 Subject: [PATCH 02/10] respect line length limit of 100 chars per line --- spec/src/agent/Belief.spec.js | 12 ++++++++---- spec/src/environment/Environment.spec.js | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/spec/src/agent/Belief.spec.js b/spec/src/agent/Belief.spec.js index d222f59..56109b4 100644 --- a/spec/src/agent/Belief.spec.js +++ b/spec/src/agent/Belief.spec.js @@ -16,20 +16,24 @@ describe('belief()', () => { ...Belief('null', null), ...Belief('array', []) } - expect(console.warn).not.toHaveBeenCalledWith('JS-son: Created belief with non-JSON object, non-JSON data type value') + expect(console.warn).not.toHaveBeenCalledWith( + 'JS-son: Created belief with non-JSON object, non-JSON data type value' + ) }) it('should not throw warning if belief is JSON.stringify-able', () => { console.warn.calls.reset() // eslint-disable-next-line no-unused-vars const belief = Belief('object', {}) - expect(console.warn).not.toHaveBeenCalledWith('JS-son: Created belief with non-JSON object, non-JSON data type value') + expect(console.warn).not.toHaveBeenCalledWith( + 'JS-son: Created belief with non-JSON object, non-JSON data type value') }) - it('should throw a warning if belief is not JSON.stringify-able and not of a JSON data type', () => { + it('should throw warning if belief isn\'t JSON.stringify-able & not of a JSON data type', () => { console.warn.calls.reset() // eslint-disable-next-line no-unused-vars const belief = Belief('function', () => {}) - expect(console.warn).toHaveBeenCalledWith('JS-son: Created belief with non-JSON object, non-JSON data type value') + expect(console.warn).toHaveBeenCalledWith( + 'JS-son: Created belief with non-JSON object, non-JSON data type value') }) }) diff --git a/spec/src/environment/Environment.spec.js b/spec/src/environment/Environment.spec.js index fca9690..d7bf7b8 100644 --- a/spec/src/environment/Environment.spec.js +++ b/spec/src/environment/Environment.spec.js @@ -26,7 +26,8 @@ describe('Environment / run()', () => { } const update = actions => { - return actions.some(action => action.actions.includes('Here, take some food!')) ? { dogHungry: false } : {} + return actions.some(action => action.actions.includes('Here, take some food!')) + ? { dogHungry: false } : {} } it('Should process agent actions', () => { From b69a68d26675ad4bfb3b4d37b0c35e870af73361 Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Fri, 1 Mar 2019 23:37:28 +0100 Subject: [PATCH 03/10] git rid of not necessary return statement --- spec/src/environment/Environment.spec.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spec/src/environment/Environment.spec.js b/spec/src/environment/Environment.spec.js index d7bf7b8..6fea589 100644 --- a/spec/src/environment/Environment.spec.js +++ b/spec/src/environment/Environment.spec.js @@ -25,10 +25,9 @@ describe('Environment / run()', () => { dogHungry: true } - const update = actions => { - return actions.some(action => action.actions.includes('Here, take some food!')) - ? { dogHungry: false } : {} - } + const update = actions => (actions.some( + action => action.actions.includes('Here, take some food!')) ? { dogHungry: false } : {} + ) it('Should process agent actions', () => { const environment = new Environment([human], state, update) From dc0eeac694bef64acd2566571db7c469794d23f3 Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Fri, 1 Mar 2019 23:39:49 +0100 Subject: [PATCH 04/10] remove "dead" file --- spec/src/js-son.spec.js | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 spec/src/js-son.spec.js diff --git a/spec/src/js-son.spec.js b/spec/src/js-son.spec.js deleted file mode 100644 index 8f4fed5..0000000 --- a/spec/src/js-son.spec.js +++ /dev/null @@ -1,7 +0,0 @@ -// import * as js_son from './src/js-son.js' - -/* describe('updateBeliefs', () => { - it('Should correclty update beliefs according to the default update function', () => { - expect(true).toBe(false) - }) -}) */ From 10ea2e08d83dbd0ce609a5feee5b9388adacf499 Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Fri, 1 Mar 2019 23:44:24 +0100 Subject: [PATCH 05/10] remove unused import --- examples/node/full.js | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/node/full.js b/examples/node/full.js index b7f4981..d2ebb72 100644 --- a/examples/node/full.js +++ b/examples/node/full.js @@ -33,7 +33,6 @@ We import the JS-son dependencies: const { Belief, Desire, - Intentions, // eslint-disable-line no-unused-vars Plan, Agent, Environment From b4eeba548e45c37ab8a10febd7ac264cd0c75cad Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Fri, 1 Mar 2019 23:48:53 +0100 Subject: [PATCH 06/10] require directly from JS object --- src/js-son.js | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/js-son.js b/src/js-son.js index 6f75856..7b03074 100644 --- a/src/js-son.js +++ b/src/js-son.js @@ -1,17 +1,10 @@ -const Belief = require('./agent/Belief') -const Desire = require('./agent/Desire') -const Intentions = require('./agent/Intentions') -const Plan = require('./agent/Plan') -const Agent = require('./agent/Agent') -const Environment = require('./environment/Environment') - const JSson = { - Belief, - Desire, - Intentions, - Plan, - Agent, - Environment + Belief: require('./agent/Belief'), + Desire: require('./agent/Desire'), + Intentions: require('./agent/Intentions'), + Plan: require('./agent/Plan'), + Agent: require('./agent/Agent'), + Environment: require('./environment/Environment') } module.exports = JSson From 5fdb619d3bcf0a845b8c2eef9721af450aba0fa0 Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Fri, 1 Mar 2019 23:59:12 +0100 Subject: [PATCH 07/10] destructure when importing --- examples/node/beliefPlan.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/examples/node/beliefPlan.js b/examples/node/beliefPlan.js index bc2bd7a..95f7059 100644 --- a/examples/node/beliefPlan.js +++ b/examples/node/beliefPlan.js @@ -2,12 +2,7 @@ We import js-son and assign Belief, Plan, Agent, and Environment to sepearate consts for the sake of convenience: */ -const JSson = require('js-son-agent') - -const Belief = JSson.Belief -const Plan = JSson.Plan -const Agent = JSson.Agent -const Environment = JSson.Environment +const { Belief, Plan, Agent, Environment } = require('js-son-agent') /* Basic example of using the basic belief-plan approach with JSson From 8da8b3b395e01819b3039e3530296708fe7485fc Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Sat, 2 Mar 2019 00:08:54 +0100 Subject: [PATCH 08/10] respect character limit in example --- examples/node/full.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/node/full.js b/examples/node/full.js index d2ebb72..fd6f783 100644 --- a/examples/node/full.js +++ b/examples/node/full.js @@ -195,8 +195,10 @@ const stateFilter = (state, agentKey, agentBeliefs) => { () => 0.5 - Math.random() ).slice(0, 2) // add some noise - let noise = Object.keys(state).filter(agentId => state[agentId].keyBelief).length < 50 * Math.random() ? [true] : [] - noise = Object.keys(state).filter(agentId => state[agentId].keyBelief).length < 29 * Math.random() ? [false] : noise + let noise = Object.keys(state).filter( + agentId => state[agentId].keyBelief).length < 50 * Math.random() ? [true] : [] + noise = Object.keys(state).filter(agentId => state[agentId].keyBelief).length < 29 * Math.random() + ? [false] : noise // combine announcements const pastReceivedAnnouncements = recentVolatileAnnouncements.concat( From 51e3601a9c890259796ec8217283f23a8b12c189 Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Sat, 2 Mar 2019 00:12:06 +0100 Subject: [PATCH 09/10] require and deconstruct in one statement --- examples/web/src/js/GameOfLife.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/examples/web/src/js/GameOfLife.js b/examples/web/src/js/GameOfLife.js index 9e95da7..04e4d2b 100644 --- a/examples/web/src/js/GameOfLife.js +++ b/examples/web/src/js/GameOfLife.js @@ -1,12 +1,7 @@ // import DOM helper for render function import $$ from 'dom7' -// import js-son -const JSson = require('js-son-agent') -// assign Belief, Plan, Agent, and Environment to separate consts -const Belief = JSson.Belief -const Plan = JSson.Plan -const Agent = JSson.Agent -const Environment = JSson.Environment +// import js-son and assign Belief, Plan, Agent, and Environment to separate consts +const { Belief, Plan, Agent, Environment } = require('js-son-agent') /* Note: beliefs will be created dynamically at a later stage From 4b2890682e2bcaef0defa1f07e16abee4afc4e5d Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Sat, 2 Mar 2019 00:15:01 +0100 Subject: [PATCH 10/10] change require to import * to be consistent in web app example * in other examples and core component code, `require` is by design, though --- examples/web/src/js/GameOfLife.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/web/src/js/GameOfLife.js b/examples/web/src/js/GameOfLife.js index 04e4d2b..8f5af68 100644 --- a/examples/web/src/js/GameOfLife.js +++ b/examples/web/src/js/GameOfLife.js @@ -1,7 +1,7 @@ // import DOM helper for render function import $$ from 'dom7' // import js-son and assign Belief, Plan, Agent, and Environment to separate consts -const { Belief, Plan, Agent, Environment } = require('js-son-agent') +import { Belief, Plan, Agent, Environment } from 'js-son-agent' /* Note: beliefs will be created dynamically at a later stage