Skip to content

Commit

Permalink
chore(refactor): simplified history maps
Browse files Browse the repository at this point in the history
  • Loading branch information
b committed Apr 12, 2020
1 parent 16aedfe commit 0800aed
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kingly",
"sideEffects": false,
"version": "0.24.0",
"version": "0.24.1",
"description": "Extended Hierarchical State Transducer library",
"repository": {
"type": "git",
Expand Down
8 changes: 4 additions & 4 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export function computeHistoryMaps(control_states) {
const {getLabel, isLeafLabel} = objectTreeLenses;
const traverse = {
strategy: PRE_ORDER,
seed: {stateList: [], stateAncestors: {[DEEP]: {}, [SHALLOW]: {}}},
seed: {stateList: [], stateAncestors: {}},
visit: (acc, traversalState, tree) => {
const treeLabel = getLabel(tree);
const controlState = Object.keys(treeLabel)[0];
Expand All @@ -393,7 +393,7 @@ export function computeHistoryMaps(control_states) {
}
else {
const parentControlState = traversalState.get(JSON.stringify(parentPath));
acc.stateAncestors[SHALLOW][controlState] = [parentControlState];
acc.stateAncestors[controlState] = [parentControlState];

const {ancestors} = path.reduce((acc, _) => {
const parentPath = acc.path.slice(0, -1);
Expand All @@ -405,7 +405,7 @@ export function computeHistoryMaps(control_states) {

return acc
}, {ancestors: [], path});
acc.stateAncestors[DEEP][controlState] = ancestors;
acc.stateAncestors[controlState] = ancestors;
}

return acc
Expand Down Expand Up @@ -554,7 +554,7 @@ export function updateHistory(history, stateAncestors, state_from_name) {
}
else {
// ancestors for the state which is exited
const ancestors = stateAncestors[DEEP][state_from_name] || [];
const ancestors = stateAncestors[state_from_name] || [];
ancestors.reduce((oldAncestor, newAncestor) => {
// set the exited state in the history of all ancestors
history[DEEP][newAncestor] = state_from_name;
Expand Down
26 changes: 13 additions & 13 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// import './no-hierarchy.specs'
// import './no-hierarchy-with-init-control-state-specs'
// import "./convert-to-plantuml.specs"
// import "./online_visualizer_translation.specs"
// import "./fsm_trace.specs"
// import "./utils.specs"
// import './hierarchy.specs'
// import './debug-settings-specs'
// import './contracts.specs'
// import './entry-actions.specs'
// import './errors-specs'
// import './contracts.ad-hoc.specs'
// import './issue-4.specs'
import './no-hierarchy.specs'
import './no-hierarchy-with-init-control-state-specs'
import "./convert-to-plantuml.specs"
import "./online_visualizer_translation.specs"
import "./fsm_trace.specs"
import "./utils.specs"
import './hierarchy.specs'
import './debug-settings-specs'
import './contracts.specs'
import './entry-actions.specs'
import './errors-specs'
import './contracts.ad-hoc.specs'
import './issue-4.specs'
import './issue-5.specs'
QUnit.dump.maxDepth = 50;
9 changes: 0 additions & 9 deletions test/utils.specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ QUnit.test("states with hierarchy", function exec_test(assert) {
const history = computeHistoryMaps(states);
assert.deepEqual(history, {
"stateAncestors": {
"deep": {
"INNER": [
"OUTER"
],
Expand All @@ -295,14 +294,6 @@ QUnit.test("states with hierarchy", function exec_test(assert) {
"outer_b": [
"OUTER"
]
},
"shallow": {
"INNER": ["OUTER"],
"inner_s": ["INNER"],
"inner_t": ["INNER"],
"outer_a": ["OUTER"],
"outer_b": ["OUTER"]
}
},
"stateList": [
"OUTER",
Expand Down

0 comments on commit 0800aed

Please sign in to comment.