Skip to content

Commit

Permalink
Merge pull request #22 from Exabyte-io/feat/SOF-6398-2
Browse files Browse the repository at this point in the history
SOF-6398-2: prettier reformat
  • Loading branch information
unsigned6 committed Nov 18, 2022
2 parents fa83d7e + 9115b2d commit dc1b5bb
Show file tree
Hide file tree
Showing 14 changed files with 297 additions and 228 deletions.
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": false,
"printWidth": 100,
"trailingComma": "all",
"tabWidth": 4
}

37 changes: 34 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"description": "WOrkflow DEfinitions",
"scripts": {
"test": "nyc --reporter=text mocha --recursive --bail --require @babel/register/lib --require tests/setup.js tests",
"lint": "eslint src tests",
"lint:fix": "eslint --fix --cache src tests",
"lint": "eslint src tests && prettier --write src tests",
"lint:fix": "eslint --fix --cache src tests && prettier --write src tests",
"transpile": "babel --out-dir dist src; node build_workflows.js",
"postinstall": "npm run transpile",
"prettier": "prettier --check src tests",
"prepare": "husky install || exit 0"
},
"repository": {
Expand Down Expand Up @@ -37,7 +38,6 @@
"@babel/preset-react": "7.16.7",
"@babel/register": "^7.16.0",
"@babel/runtime-corejs3": "7.16.8",
"@exabyte-io/eslint-config": "^2022.11.16-0",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"mixwith": "^0.1.1",
Expand All @@ -47,16 +47,19 @@
"devDependencies": {
"@exabyte-io/ade.js": "2022.11.16-0",
"@exabyte-io/code.js": "2022.11.11-0",
"@exabyte-io/eslint-config": "^2022.11.17-0",
"@exabyte-io/ide.js": "2022.7.28-1",
"@exabyte-io/made.js": "2022.6.15-0",
"@exabyte-io/mode.js": "2022.10.11-0",
"chai": "^4.3.4",
"eslint": "7.32.0",
"eslint-config-airbnb": "19.0.2",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-exports": "^1.0.0-beta.2",
"eslint-plugin-import": "2.25.3",
"eslint-plugin-jsdoc": "37.1.0",
"eslint-plugin-jsx-a11y": "6.5.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "7.30.0",
"eslint-plugin-simple-import-sort": "7.0.0",
"husky": "^7.0.4",
Expand All @@ -75,6 +78,7 @@
"node": ">=12.0.0"
},
"lint-staged": {
"*.js": "eslint --cache --fix"
"*.js": "eslint --cache --fix",
"*.{js,css}": "prettier --write"
}
}
215 changes: 109 additions & 106 deletions src/subworkflows/convergence.js
Original file line number Diff line number Diff line change
@@ -1,122 +1,125 @@
import { UNIT_TYPES } from "../enums";

export const ConvergenceMixin = (superclass) => class extends superclass {
addConvergence({
parameter,
parameterInitial,
result,
resultInitial,
condition,
operator,
tolerance,
maxOccurrences,
}) {
// RF: added TODO comments for future improvements
export const ConvergenceMixin = (superclass) =>
class extends superclass {
addConvergence({
parameter,
parameterInitial,
result,
resultInitial,
condition,
operator,
tolerance,
maxOccurrences,
}) {
// RF: added TODO comments for future improvements

const { units } = this;
// Find unit to converge: should contain passed result in its results list
// TODO: make user to select unit for convergence explicitly
const unitForConvergence = units.find((x) => x.resultNames.find((name) => name === result));
const { units } = this;
// Find unit to converge: should contain passed result in its results list
// TODO: make user to select unit for convergence explicitly
const unitForConvergence = units.find((x) =>
x.resultNames.find((name) => name === result),
);

if (!unitForConvergence) {
// eslint-disable-next-line no-undef
sAlert.error(
if (!unitForConvergence) {
// eslint-disable-next-line no-undef
sAlert.error(
`Subworkflow does not contain unit with '${result}' as extracted property.`,
);
throw new Error("There is no result to converge");
}
);
throw new Error("There is no result to converge");
}

// Replace kgrid to be ready for convergence
// TODO: kgrid should be abstracted and selected by user
unitForConvergence.updateContext({
kgrid: {
dimensions: [`{{${parameter}}}`, `{{${parameter}}}`, `{{${parameter}}}`],
shifts: [0, 0, 0],
},
isKgridEdited: true,
isUsingJinjaVariables: true,
});
// Replace kgrid to be ready for convergence
// TODO: kgrid should be abstracted and selected by user
unitForConvergence.updateContext({
kgrid: {
dimensions: [`{{${parameter}}}`, `{{${parameter}}}`, `{{${parameter}}}`],
shifts: [0, 0, 0],
},
isKgridEdited: true,
isUsingJinjaVariables: true,
});

const prevResult = "prev_result";
const prevResult = "prev_result";

// Assignment with result's initial value
const prevResultInit = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
head: true,
operand: prevResult,
value: resultInitial,
});
// Assignment with result's initial value
const prevResultInit = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
head: true,
operand: prevResult,
value: resultInitial,
});

// Assignment with initial value of convergence parameter
const paramInit = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
operand: parameter,
value: parameterInitial,
});
// Assignment with initial value of convergence parameter
const paramInit = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
operand: parameter,
value: parameterInitial,
});

// Assignment for storing iteration result: extracts 'result' from convergence unit scope
const storePrevResult = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
input: [
{
scope: unitForConvergence.flowchartId,
name: result,
},
],
operand: prevResult,
value: result,
});
// Assignment for storing iteration result: extracts 'result' from convergence unit scope
const storePrevResult = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
input: [
{
scope: unitForConvergence.flowchartId,
name: result,
},
],
operand: prevResult,
value: result,
});

// Assignment for convergence param increase
const nextStep = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
input: [],
operand: parameter,
value: `${parameter} + 1`,
next: unitForConvergence.flowchartId,
});
// Assignment for convergence param increase
const nextStep = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
input: [],
operand: parameter,
value: `${parameter} + 1`,
next: unitForConvergence.flowchartId,
});

// Final step of convergence
const exit = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
name: "exit",
input: [],
operand: parameter,
value: `${parameter} + 0`,
});
// Final step of convergence
const exit = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
name: "exit",
input: [],
operand: parameter,
value: `${parameter} + 0`,
});

// Final step of convergence
const storeResult = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
input: [
{
scope: unitForConvergence.flowchartId,
name: result,
},
],
operand: result,
value: result,
});
// Final step of convergence
const storeResult = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
input: [
{
scope: unitForConvergence.flowchartId,
name: result,
},
],
operand: result,
value: result,
});

// Convergence condition unit
const conditionUnit = this._UnitFactory.create({
type: UNIT_TYPES.condition,
statement: `${condition} ${operator} ${tolerance}`,
then: exit.flowchartId,
else: storePrevResult.flowchartId,
maxOccurrences,
next: storePrevResult.flowchartId,
});
// Convergence condition unit
const conditionUnit = this._UnitFactory.create({
type: UNIT_TYPES.condition,
statement: `${condition} ${operator} ${tolerance}`,
then: exit.flowchartId,
else: storePrevResult.flowchartId,
maxOccurrences,
next: storePrevResult.flowchartId,
});

this.addUnit(prevResultInit, true);
this.addUnit(paramInit, true);
this.addUnit(storeResult);
this.addUnit(conditionUnit);
this.addUnit(storePrevResult);
this.addUnit(nextStep);
this.addUnit(exit);
this.addUnit(prevResultInit, true);
this.addUnit(paramInit, true);
this.addUnit(storeResult);
this.addUnit(conditionUnit);
this.addUnit(storePrevResult);
this.addUnit(nextStep);
this.addUnit(exit);

// `addUnit` adjusts the `next` field, hence the below.
nextStep.next = unitForConvergence.flowchartId;
}
};
// `addUnit` adjusts the `next` field, hence the below.
nextStep.next = unitForConvergence.flowchartId;
}
};

0 comments on commit dc1b5bb

Please sign in to comment.