Skip to content

Commit

Permalink
Use const instead of let where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb531 committed Jan 16, 2025
1 parent 0aa3519 commit e6c026a
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 91 deletions.
2 changes: 1 addition & 1 deletion scripts/components/reference.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ReferenceComponent {
exampleExpressionString.indexOf(exampleVariableName) !== -1 &&
app.variables.length < i + 1
) {
let lastVariable = app.variables.get(app.variables.length - 1);
const lastVariable = app.variables.get(app.variables.length - 1);
app.variables.insert(app.variables.length, {
name: app.variables.getNextVariableName(lastVariable)
});
Expand Down
12 changes: 6 additions & 6 deletions scripts/components/table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ class TableComponent {
}

getExpressionIndex(buttonElem) {
let expressionElem = buttonElem.parentNode.parentNode;
const expressionElem = buttonElem.parentNode.parentNode;
return Number(expressionElem.getAttribute('data-index'));
}

updateExpressionString(clickEvent) {
let expression = this.app.expressions.get(this.getExpressionIndex(clickEvent.target));
const expression = this.app.expressions.get(this.getExpressionIndex(clickEvent.target));
expression.string = clickEvent.target.value;
this.app.save();
}

addExpression(clickEvent) {
let expressionIndex = this.getExpressionIndex(clickEvent.target);
let expression = this.app.expressions.get(expressionIndex);
const expressionIndex = this.getExpressionIndex(clickEvent.target);
const expression = this.app.expressions.get(expressionIndex);
this.app.expressions.insert(expressionIndex + 1, {
string: expression.string
});
Expand Down Expand Up @@ -105,7 +105,7 @@ class TableComponent {
return (
<tr>
{this.app.variables.map((variable) => {
let varValue = varValues[variable.name];
const varValue = varValues[variable.name];
return (
<td
className={clsx({
Expand All @@ -118,7 +118,7 @@ class TableComponent {
);
})}
{this.app.expressions.map((expression) => {
let exprValue = expression.evaluate(varValues);
const exprValue = expression.evaluate(varValues);
return (
<td
className={clsx({
Expand Down
10 changes: 5 additions & 5 deletions scripts/components/variable-collection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class VariableCollectionComponent {
}

getVariableIndex(buttonElem) {
let variableElem = buttonElem.parentNode.parentNode;
const variableElem = buttonElem.parentNode.parentNode;
return Number(variableElem.getAttribute('data-index'));
}

Expand All @@ -18,16 +18,16 @@ class VariableCollectionComponent {
(this.validNamePattern.test(inputEvent.target.value) &&
this.app.variables.checkNameAvailability(inputEvent.target.value))
) {
let variable = this.app.variables.get(this.getVariableIndex(inputEvent.target));
const variable = this.app.variables.get(this.getVariableIndex(inputEvent.target));
variable.name = inputEvent.target.value;
this.app.save();
}
}

addVariable(clickEvent) {
let variableIndex = this.getVariableIndex(clickEvent.target);
let variable = this.app.variables.get(variableIndex);
let newVariableName = this.app.variables.getNextVariableName(variable);
const variableIndex = this.getVariableIndex(clickEvent.target);
const variable = this.app.variables.get(variableIndex);
const newVariableName = this.app.variables.getNextVariableName(variable);
this.app.variables.insert(variableIndex + 1, {
name: newVariableName
});
Expand Down
2 changes: 1 addition & 1 deletion scripts/models/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class App {
App.storageKey = 'truthy-v3';

App.restore = function () {
let appStr = localStorage.getItem(App.storageKey);
const appStr = localStorage.getItem(App.storageKey);
if (appStr !== null) {
return new App(JSON.parse(appStr));
} else {
Expand Down
6 changes: 3 additions & 3 deletions scripts/models/variable-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class VariableCollection extends Collection {
// Transform all possible permutations of true/false values for this collection
// of variables using the provided callback
mapPermutations(callback) {
let variables = this;
const variables = this;
// An object where each key is a variable name and each value is a boolean
// representing the current value of that variable
let currentVarValues = fromPairs(
const currentVarValues = fromPairs(
variables.map((variable) => {
// Initialize all variable values to false
return [variable.name, false];
Expand All @@ -47,7 +47,7 @@ class VariableCollection extends Collection {
// the given base variable)
getNextVariableName(baseVariable) {
// Create a list of variable names already in use
let variableCharCodes = this.map((variable) => variable.name.charCodeAt(0));
const variableCharCodes = this.map((variable) => variable.name.charCodeAt(0));
// Look for the next letter that isn't already in use
let nextVarCharCode = baseVariable.name.charCodeAt(0);
do {
Expand Down
20 changes: 10 additions & 10 deletions test/app.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import App from '../scripts/models/app.js';

describe('app', () => {
it('should initialize with no arguments', () => {
let app = new App();
const app = new App();
expect(app).toHaveProperty('variables');
expect(app.variables).toHaveLength(2);
expect(app).toHaveProperty('expressions');
expect(app.expressions).toHaveLength(3);
});

it('should initialize with arguments', () => {
let app = new App({
const app = new App({
variables: { items: [{ name: 'a' }, { name: 'b' }, { name: 'c' }] },
expressions: { items: [{ string: 'a xor b' }, { string: 'a nand b' }] }
});
Expand All @@ -26,34 +26,34 @@ describe('app', () => {
});

it('should serialize to JSON object', () => {
let serializedApp = {
const serializedApp = {
variables: { items: [{ name: 'a' }, { name: 'b' }, { name: 'c' }] },
expressions: { items: [{ string: 'a xor b' }, { string: 'a nand b' }] }
};
let app = new App(serializedApp);
const app = new App(serializedApp);
expect(app.serialize()).toEqual(serializedApp);
});

it('should save serialized app to disk', () => {
let serializedApp = {
const serializedApp = {
variables: { items: [{ name: 'a' }, { name: 'b' }, { name: 'c' }] },
expressions: { items: [{ string: 'a xor b' }, { string: 'a nand b' }] }
};
let app = new App(serializedApp);
const app = new App(serializedApp);
app.save();
let restoredAppStr = localStorage.getItem('truthy-v3');
const restoredAppStr = localStorage.getItem('truthy-v3');
expect(restoredAppStr).toEqual(JSON.stringify(serializedApp));
localStorage.removeItem('truthy-v3');
});

it('should restore serialized app to disk', () => {
let serializedApp = {
const serializedApp = {
variables: { items: [{ name: 'a' }, { name: 'b' }, { name: 'c' }] },
expressions: { items: [{ string: 'a xor b' }, { string: 'a nand b' }] }
};
let app = new App(serializedApp);
const app = new App(serializedApp);
app.save();
let restoredApp = App.restore();
const restoredApp = App.restore();
expect(restoredApp).toBeTruthy();
expect(restoredApp.serialize()).toEqual(serializedApp);
});
Expand Down
28 changes: 14 additions & 14 deletions test/collection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('collection', () => {
}

it('should initialize with list of items', () => {
let collection = new Collection({
const collection = new Collection({
SubCollectionItem: DummyItem,
items: [{ foo: 'abc' }, { foo: 'xyz' }]
});
Expand All @@ -23,16 +23,16 @@ describe('collection', () => {
});

it('should serialize to a JSON object', () => {
let serializedCollection = { items: [{ foo: 'abc' }, { foo: 'xyz' }] };
let collection = new Collection({
const serializedCollection = { items: [{ foo: 'abc' }, { foo: 'xyz' }] };
const collection = new Collection({
SubCollectionItem: DummyItem,
items: serializedCollection.items
});
expect(collection.serialize()).toEqual(serializedCollection);
});

it('should get item by its index', () => {
let collection = new Collection({
const collection = new Collection({
SubCollectionItem: DummyItem,
items: [{ foo: 'abc' }, { foo: 'xyz' }]
});
Expand All @@ -41,7 +41,7 @@ describe('collection', () => {
});

it('should insert new item', () => {
let collection = new Collection({
const collection = new Collection({
SubCollectionItem: DummyItem,
items: [{ foo: 'abc' }, { foo: 'xyz' }]
});
Expand All @@ -52,7 +52,7 @@ describe('collection', () => {
});

it('should remove existing item', () => {
let collection = new Collection({
const collection = new Collection({
SubCollectionItem: DummyItem,
items: [{ foo: 'abc' }, { foo: 'xyz' }, { foo: 'def' }]
});
Expand All @@ -63,23 +63,23 @@ describe('collection', () => {
});

it('should iterate over items', () => {
let collection = new Collection({
const collection = new Collection({
SubCollectionItem: DummyItem,
items: [{ foo: 'abc' }, { foo: 'xyz' }, { foo: 'def' }]
});
let iteratedItems = [];
const iteratedItems = [];
collection.forEach((item) => {
iteratedItems.push(item);
});
expect(iteratedItems).toEqual(collection.items);
});

it('should filter items', () => {
let collection = new Collection({
const collection = new Collection({
SubCollectionItem: DummyItem,
items: [{ foo: 'abc' }, { foo: 'xyz' }, { foo: 'bef' }, { foo: 'ghi' }]
});
let itemsWithoutB = collection.filter((item) => {
const itemsWithoutB = collection.filter((item) => {
return item.foo.indexOf('b') === -1;
});
expect(itemsWithoutB).toHaveLength(2);
Expand All @@ -88,26 +88,26 @@ describe('collection', () => {
});

it('should map items', () => {
let collection = new Collection({
const collection = new Collection({
SubCollectionItem: DummyItem,
items: [{ foo: 'abc' }, { foo: 'xyz' }, { foo: 'def' }]
});
let iteratedItems = collection.map((item) => {
const iteratedItems = collection.map((item) => {
return item;
});
expect(iteratedItems).toEqual(collection.items);
});

it('should get collection length', () => {
let collection = new Collection({
const collection = new Collection({
SubCollectionItem: DummyItem,
items: [{ foo: 'abc' }, { foo: 'xyz' }, { foo: 'def' }]
});
expect(collection.length).toEqual(3);
});

it('should set collection length', () => {
let collection = new Collection({
const collection = new Collection({
SubCollectionItem: DummyItem,
items: [{ foo: 'abc' }, { foo: 'xyz' }, { foo: 'def' }]
});
Expand Down
2 changes: 1 addition & 1 deletion test/expression-collection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Expression from '../scripts/models/expression.js';

describe('expression collection', () => {
it('should initialize with list of expressions', () => {
let expressions = new ExpressionCollection({
const expressions = new ExpressionCollection({
items: [{ string: 'a xor b' }, { string: 's nand t' }]
});
expect(expressions).toHaveProperty('items');
Expand Down
Loading

0 comments on commit e6c026a

Please sign in to comment.