Skip to content

Commit 929ba4b

Browse files
committed
refactor: simplify variable names
1 parent 5f4fc0c commit 929ba4b

File tree

2 files changed

+82
-82
lines changed

2 files changed

+82
-82
lines changed

src/object-graph.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ export class ObjectGraph<NodeValue extends Record<string, unknown>> {
124124
* @since 1.0.0
125125
*/
126126
public toAdded(nodeValue: NodeValue): ObjectGraph<NodeValue> {
127-
const copiedObjectGraph = this.copy();
128-
copiedObjectGraph.add(nodeValue);
129-
return copiedObjectGraph;
127+
const copiedGraph = this.copy();
128+
copiedGraph.add(nodeValue);
129+
return copiedGraph;
130130
}
131131

132132
/**
@@ -149,9 +149,9 @@ export class ObjectGraph<NodeValue extends Record<string, unknown>> {
149149
* @since 1.0.0
150150
*/
151151
public toUpdated(nodeValue: NodeValue): ObjectGraph<NodeValue> {
152-
const copiedObjectGraph = this.copy();
153-
copiedObjectGraph.update(nodeValue);
154-
return copiedObjectGraph;
152+
const copiedGraph = this.copy();
153+
copiedGraph.update(nodeValue);
154+
return copiedGraph;
155155
}
156156

157157
/**
@@ -176,9 +176,9 @@ export class ObjectGraph<NodeValue extends Record<string, unknown>> {
176176
* @since 1.0.0
177177
*/
178178
public toRemoved(nodeKey: string): ObjectGraph<NodeValue> {
179-
const copiedObjectGraph = this.copy();
180-
copiedObjectGraph.remove(nodeKey);
181-
return copiedObjectGraph;
179+
const copiedGraph = this.copy();
180+
copiedGraph.remove(nodeKey);
181+
return copiedGraph;
182182
}
183183

184184
/**

tests/object-graph.test.ts

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -11,69 +11,69 @@ import { ObjectGraph } from "../src/object-graph";
1111
describe("length", () => {
1212
test("gets the length of the object graph", () => {
1313
const shirtToAdd: Shirt = { sku: "9", color: "orange", size: "small" };
14-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
14+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
1515

16-
expect(shirtsObjectGraph.length).toBe(8);
16+
expect(shirtsGraph.length).toBe(8);
1717

18-
shirtsObjectGraph.add(shirtToAdd);
18+
shirtsGraph.add(shirtToAdd);
1919

20-
expect(shirtsObjectGraph.length).toBe(9);
20+
expect(shirtsGraph.length).toBe(9);
2121
});
2222
});
2323

2424
describe("size", () => {
2525
test("gets the size of the object graph", () => {
2626
const shirtToAdd: Shirt = { sku: "9", color: "orange", size: "small" };
27-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
27+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
2828

29-
expect(shirtsObjectGraph.size).toBe(8);
29+
expect(shirtsGraph.size).toBe(8);
3030

31-
shirtsObjectGraph.add(shirtToAdd);
31+
shirtsGraph.add(shirtToAdd);
3232

33-
expect(shirtsObjectGraph.size).toBe(9);
33+
expect(shirtsGraph.size).toBe(9);
3434
});
3535
});
3636

3737
describe("keys()", () => {
3838
test("gets an iterator object that contains the keys of the object graph", () => {
39-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
39+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
4040

41-
const shirtsObjectGraphKeysIterator = shirtsObjectGraph.keys();
42-
const shirtsObjectGraphKeys = Array.from(shirtsObjectGraphKeysIterator);
41+
const shirtsGraphKeysIterator = shirtsGraph.keys();
42+
const shirtsGraphKeys = Array.from(shirtsGraphKeysIterator);
4343

44-
expectTypeOf(shirtsObjectGraphKeysIterator[Symbol.iterator]).toBeFunction();
45-
expect(shirtsObjectGraphKeys).toEqual(["1", "2", "3", "4", "5", "6", "7", "8"]);
44+
expectTypeOf(shirtsGraphKeysIterator[Symbol.iterator]).toBeFunction();
45+
expect(shirtsGraphKeys).toEqual(["1", "2", "3", "4", "5", "6", "7", "8"]);
4646
});
4747
});
4848

4949
describe("values()", () => {
5050
test("gets an iterator object that contains the values of the object graph", () => {
51-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
51+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
5252

53-
const shirtsObjectGraphValuesIterator = shirtsObjectGraph.values();
54-
const shirtsObjectGraphValues = Array.from(shirtsObjectGraphValuesIterator);
53+
const shirtsGraphValuesIterator = shirtsGraph.values();
54+
const shirtsGraphValues = Array.from(shirtsGraphValuesIterator);
5555

56-
expectTypeOf(shirtsObjectGraphValuesIterator[Symbol.iterator]).toBeFunction();
57-
expect(shirtsObjectGraphValues).toHaveLength(8);
58-
expect(shirtsObjectGraphValues[0]).toStrictEqual(shirtsMock[0]);
56+
expectTypeOf(shirtsGraphValuesIterator[Symbol.iterator]).toBeFunction();
57+
expect(shirtsGraphValues).toHaveLength(8);
58+
expect(shirtsGraphValues[0]).toStrictEqual(shirtsMock[0]);
5959
});
6060
});
6161

6262
describe("get()", () => {
6363
test("logs an error when there is no node with the provided key in the object graph", () => {
6464
const consoleErrorSpy = vi.spyOn(console, "error");
65-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
65+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
6666

67-
const returnedNode = shirtsObjectGraph.get("9");
67+
const returnedNode = shirtsGraph.get("9");
6868

6969
expect(consoleErrorSpy).toHaveBeenCalled();
7070
expect(returnedNode).toBeUndefined();
7171
});
7272

7373
test("gets a node of the object graph", () => {
74-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
74+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
7575

76-
const returnedNode = shirtsObjectGraph.get(shirtsMock[0].sku);
76+
const returnedNode = shirtsGraph.get(shirtsMock[0].sku);
7777

7878
expect(returnedNode?.color).toBe(shirtsMock[0].color);
7979
expect(returnedNode?.size).toBe(shirtsMock[0].size);
@@ -82,59 +82,59 @@ describe("get()", () => {
8282

8383
describe("copy()", () => {
8484
test("gets a copy of the original object graph", () => {
85-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
85+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
8686

87-
const copiedShirtsObjectGraph = shirtsObjectGraph.copy();
87+
const copiedShirtsGraph = shirtsGraph.copy();
8888

89-
expect(shirtsObjectGraph.get("1")).toEqual(copiedShirtsObjectGraph.get("1"));
89+
expect(shirtsGraph.get("1")).toEqual(copiedShirtsGraph.get("1"));
9090
});
9191
});
9292

9393
describe("subgraph()", () => {
9494
test("gets a subgraph of the original object graph", () => {
95-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
96-
const shirtsObjectSubgraph = shirtsObjectGraph.subgraph(["1", "2", "3", "4"]);
95+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
96+
const shirtsSubgraph = shirtsGraph.subgraph(["1", "2", "3", "4"]);
9797

98-
expect(shirtsObjectGraph).toHaveLength(8);
99-
expect(shirtsObjectSubgraph).toHaveLength(4);
98+
expect(shirtsGraph).toHaveLength(8);
99+
expect(shirtsSubgraph).toHaveLength(4);
100100
});
101101
});
102102

103103
describe("add()", () => {
104104
test("logs an error when a node with the same key already exists in the object graph", () => {
105105
const consoleErrorSpy = vi.spyOn(console, "error");
106-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
106+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
107107

108-
shirtsObjectGraph.add(shirtsMock[0]);
108+
shirtsGraph.add(shirtsMock[0]);
109109

110110
expect(consoleErrorSpy).toHaveBeenCalled();
111111
});
112112

113113
test("adds a node to the object graph", () => {
114-
const shirtsObjectGraph = new ObjectGraph<Shirt>([], (shirt) => shirt.sku);
114+
const shirtsGraph = new ObjectGraph<Shirt>([], (shirt) => shirt.sku);
115115

116-
shirtsObjectGraph.add(shirtsMock[0]);
116+
shirtsGraph.add(shirtsMock[0]);
117117

118-
expect(shirtsObjectGraph.get("1")).toEqual(shirtsMock[0]);
118+
expect(shirtsGraph.get("1")).toEqual(shirtsMock[0]);
119119
});
120120
});
121121

122122
describe("toAdded()", () => {
123123
test("gets a copy of the original object graph with a received node added", () => {
124124
const consoleErrorSpy = vi.spyOn(console, "error");
125-
const shirtsObjectGraph = new ObjectGraph<Shirt>([], (shirt) => shirt.sku);
125+
const shirtsGraph = new ObjectGraph<Shirt>([], (shirt) => shirt.sku);
126126

127-
const copiedShirtsObjectGraph = shirtsObjectGraph.toAdded(shirtsMock[0]);
127+
const copiedShirtsGraph = shirtsGraph.toAdded(shirtsMock[0]);
128128

129-
expect(shirtsObjectGraph.size).toBe(0);
130-
expect(copiedShirtsObjectGraph.size).toBe(1);
129+
expect(shirtsGraph.size).toBe(0);
130+
expect(copiedShirtsGraph.size).toBe(1);
131131

132-
const returnedNodeFromCopy = copiedShirtsObjectGraph.get("1");
132+
const returnedNodeFromCopy = copiedShirtsGraph.get("1");
133133

134134
expect(consoleErrorSpy).not.toHaveBeenCalled();
135135
expect(returnedNodeFromCopy).toBeDefined();
136136

137-
const returnedNodeFromOriginal = shirtsObjectGraph.get("1");
137+
const returnedNodeFromOriginal = shirtsGraph.get("1");
138138

139139
expect(consoleErrorSpy).toHaveBeenCalled();
140140
expect(returnedNodeFromOriginal).toBeUndefined();
@@ -144,62 +144,62 @@ describe("toAdded()", () => {
144144
describe("update()", () => {
145145
test("logs an error when there is no node with the same key in the object graph", () => {
146146
const consoleErrorSpy = vi.spyOn(console, "error");
147-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
147+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
148148

149-
shirtsObjectGraph.update(extraShirtsMock[0]);
149+
shirtsGraph.update(extraShirtsMock[0]);
150150

151151
expect(consoleErrorSpy).toHaveBeenCalled();
152152
});
153153

154154
test("updates a node in the object graph", () => {
155155
const shirtToUpdate: Shirt = { sku: "1", color: "red", size: "large" };
156-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
156+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
157157

158-
expect(shirtsObjectGraph.get("1")?.size).toBe("small");
158+
expect(shirtsGraph.get("1")?.size).toBe("small");
159159

160-
shirtsObjectGraph.update(shirtToUpdate);
160+
shirtsGraph.update(shirtToUpdate);
161161

162-
expect(shirtsObjectGraph.get("1")?.size).toBe("large");
162+
expect(shirtsGraph.get("1")?.size).toBe("large");
163163
});
164164
});
165165

166166
describe("toUpdated()", () => {
167167
test("gets a copy of the original object graph with a received node updated", () => {
168168
const shirtToUpdate: Shirt = { sku: "1", color: "red", size: "large" };
169-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
169+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
170170

171-
const copiedShirtsObjectGraph = shirtsObjectGraph.toUpdated(shirtToUpdate);
171+
const copiedShirtsGraph = shirtsGraph.toUpdated(shirtToUpdate);
172172

173-
expect(shirtsObjectGraph.get("1")?.size).toBe("small");
174-
expect(copiedShirtsObjectGraph.get("1")?.size).toBe("large");
173+
expect(shirtsGraph.get("1")?.size).toBe("small");
174+
expect(copiedShirtsGraph.get("1")?.size).toBe("large");
175175
});
176176
});
177177

178178
describe("remove()", () => {
179179
test("logs an error when there is no node with the provided key in the object graph", () => {
180180
const consoleErrorSpy = vi.spyOn(console, "error");
181-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
181+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
182182

183-
const returnedNode = shirtsObjectGraph.remove("9");
183+
const returnedNode = shirtsGraph.remove("9");
184184

185185
expect(consoleErrorSpy).toHaveBeenCalled();
186186
expect(returnedNode).toBeUndefined();
187187
});
188188

189189
test("removes a node from the object graph", () => {
190190
const consoleErrorSpy = vi.spyOn(console, "error");
191-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
191+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
192192

193-
const returnedNodeFromFirstAttempt = shirtsObjectGraph.get("1");
193+
const returnedNodeFromFirstAttempt = shirtsGraph.get("1");
194194

195195
expect(consoleErrorSpy).not.toHaveBeenCalled();
196196
expect(returnedNodeFromFirstAttempt).toBeDefined();
197197

198-
shirtsObjectGraph.remove("1");
198+
shirtsGraph.remove("1");
199199

200200
expect(consoleErrorSpy).not.toHaveBeenCalled();
201201

202-
const returnedNodeFromSecondAttempt = shirtsObjectGraph.get("1");
202+
const returnedNodeFromSecondAttempt = shirtsGraph.get("1");
203203

204204
expect(consoleErrorSpy).toHaveBeenCalled();
205205
expect(returnedNodeFromSecondAttempt).toBeUndefined();
@@ -209,19 +209,19 @@ describe("remove()", () => {
209209
describe("toRemoved()", () => {
210210
test("gets a copy of the original object graph with a received node removed", () => {
211211
const consoleErrorSpy = vi.spyOn(console, "error");
212-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
212+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
213213

214-
const copiedShirtsObjectGraph = shirtsObjectGraph.toRemoved("1");
214+
const copiedShirtsGraph = shirtsGraph.toRemoved("1");
215215

216-
expect(shirtsObjectGraph.size).toBe(8);
217-
expect(copiedShirtsObjectGraph.size).toBe(7);
216+
expect(shirtsGraph.size).toBe(8);
217+
expect(copiedShirtsGraph.size).toBe(7);
218218

219-
const returnedNodeFromOriginal = shirtsObjectGraph.get("1");
219+
const returnedNodeFromOriginal = shirtsGraph.get("1");
220220

221221
expect(consoleErrorSpy).not.toHaveBeenCalled();
222222
expect(returnedNodeFromOriginal).toBeDefined();
223223

224-
const returnedNodeFromCopy = copiedShirtsObjectGraph.get("1");
224+
const returnedNodeFromCopy = copiedShirtsGraph.get("1");
225225

226226
expect(consoleErrorSpy).toHaveBeenCalled();
227227
expect(returnedNodeFromCopy).toBeUndefined();
@@ -230,19 +230,19 @@ describe("toRemoved()", () => {
230230

231231
describe("valuesOf()", () => {
232232
test("gets all values of the provided property", () => {
233-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
233+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
234234

235-
const sizePropertyValues = shirtsObjectGraph.valuesOf("size");
235+
const sizePropertyValues = shirtsGraph.valuesOf("size");
236236

237237
expect(sizePropertyValues).toContain("small");
238238
expect(sizePropertyValues).toContain("medium");
239239
expect(sizePropertyValues).toContain("large");
240240
});
241241

242242
test("gets all values of the provided property from selected nodes", () => {
243-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
243+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
244244

245-
const sizePropertyValues = shirtsObjectGraph.valuesOf("size", ["1", "2", "3", "4"]);
245+
const sizePropertyValues = shirtsGraph.valuesOf("size", ["1", "2", "3", "4"]);
246246

247247
expect(sizePropertyValues).toContain("small");
248248
expect(sizePropertyValues).toContain("medium");
@@ -254,9 +254,9 @@ describe("match()", () => {
254254
test("gets all nodes that match with the provided shape", () => {
255255
const colorsToMatch: Color[] = ["red", "blue"];
256256
const sizesToMatch: Size[] = ["small", "medium"];
257-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
257+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
258258

259-
const matchedShirts = shirtsObjectGraph.match({
259+
const matchedShirts = shirtsGraph.match({
260260
color: colorsToMatch,
261261
size: sizesToMatch,
262262
});
@@ -270,9 +270,9 @@ describe("match()", () => {
270270

271271
test("gets matched nodes ignoring undefined value in the shape", () => {
272272
const colorsToMatch: Color[] = ["yellow", "green"];
273-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
273+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
274274

275-
const matchedShirts = shirtsObjectGraph.match({
275+
const matchedShirts = shirtsGraph.match({
276276
color: colorsToMatch,
277277
size: undefined,
278278
});
@@ -284,9 +284,9 @@ describe("match()", () => {
284284
});
285285

286286
test("gets all nodes for an empty shape", () => {
287-
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
287+
const shirtsGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);
288288

289-
const matchedShirts = shirtsObjectGraph.match({});
289+
const matchedShirts = shirtsGraph.match({});
290290

291291
expect(matchedShirts).toHaveLength(8);
292292
});

0 commit comments

Comments
 (0)