Skip to content

Commit 15cf992

Browse files
committed
Remove method chaining and change delay() to static
1 parent 5394724 commit 15cf992

File tree

8 files changed

+95
-96
lines changed

8 files changed

+95
-96
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "algorithm-visualizer",
3-
"version": "2.3.1",
3+
"version": "2.3.2",
44
"description": "Visualization Library for JavaScript",
55
"keywords": [
66
"algorithm",

src/Array1DTracer.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import { Array2DTracer, ChartTracer } from './';
22

33
class Array1DTracer extends Array2DTracer {
4-
set(array1d?: any[]): this {
5-
return this.command('set', arguments);
4+
set(array1d?: any[]) {
5+
this.command('set', arguments);
66
}
77

8-
patch(x: number, v?: any): this {
9-
return this.command('patch', arguments);
8+
patch(x: number, v?: any) {
9+
this.command('patch', arguments);
1010
}
1111

12-
depatch(x: number): this {
13-
return this.command('depatch', arguments);
12+
depatch(x: number) {
13+
this.command('depatch', arguments);
1414
}
1515

16-
select(sx: number, ex?: number): this {
17-
return this.command('select', arguments);
16+
select(sx: number, ex?: number) {
17+
this.command('select', arguments);
1818
}
1919

20-
deselect(sx: number, ex?: number): this {
21-
return this.command('deselect', arguments);
20+
deselect(sx: number, ex?: number) {
21+
this.command('deselect', arguments);
2222
}
2323

24-
chart(chartTracer: ChartTracer): this {
25-
return this.command('chart', arguments);
24+
chart(chartTracer: ChartTracer) {
25+
this.command('chart', arguments);
2626
}
2727
}
2828

src/Array2DTracer.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
import { Tracer } from './';
22

33
class Array2DTracer extends Tracer {
4-
set(array2d?: any[][]): this {
5-
return this.command('set', arguments);
4+
set(array2d?: any[][]) {
5+
this.command('set', arguments);
66
}
77

8-
patch(x: number, y: number, v?: any): this {
9-
return this.command('patch', arguments);
8+
patch(x: number, y: number, v?: any) {
9+
this.command('patch', arguments);
1010
}
1111

12-
depatch(x: number, y: number): this {
13-
return this.command('depatch', arguments);
12+
depatch(x: number, y: number) {
13+
this.command('depatch', arguments);
1414
}
1515

16-
select(sx: number, sy: number, ex?: number, ey?: number): this {
17-
return this.command('select', arguments);
16+
select(sx: number, sy: number, ex?: number, ey?: number) {
17+
this.command('select', arguments);
1818
}
1919

20-
selectRow(x: number, sy: number, ey: number): this {
21-
return this.command('selectRow', arguments);
20+
selectRow(x: number, sy: number, ey: number) {
21+
this.command('selectRow', arguments);
2222
}
2323

24-
selectCol(y: number, sx: number, ex: number): this {
25-
return this.command('selectCol', arguments);
24+
selectCol(y: number, sx: number, ex: number) {
25+
this.command('selectCol', arguments);
2626
}
2727

28-
deselect(sx: number, sy: number, ex?: number, ey?: number): this {
29-
return this.command('deselect', arguments);
28+
deselect(sx: number, sy: number, ex?: number, ey?: number) {
29+
this.command('deselect', arguments);
3030
}
3131

32-
deselectRow(x: number, sy: number, ey: number): this {
33-
return this.command('deselectRow', arguments);
32+
deselectRow(x: number, sy: number, ey: number) {
33+
this.command('deselectRow', arguments);
3434
}
3535

36-
deselectCol(y: number, sx: number, ex: number): this {
37-
return this.command('deselectCol', arguments);
36+
deselectCol(y: number, sx: number, ex: number) {
37+
this.command('deselectCol', arguments);
3838
}
3939
}
4040

src/Commander.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Commander {
1414
private static objectCount = 0;
1515
public static commands: Command[] = [];
1616

17-
static command(key: string | null, method: string, iArguments: IArguments): Commander {
17+
static command(key: string | null, method: string, iArguments: IArguments) {
1818
const args = Array.from(iArguments);
1919
this.commands.push({
2020
key,
@@ -23,38 +23,24 @@ class Commander {
2323
});
2424
if (this.commands.length > MAX_COMMANDS) throw new Error('Too Many Commands');
2525
if (this.objectCount > MAX_OBJECTS) throw new Error('Too Many Objects');
26-
return (<any>this);
27-
}
28-
29-
static setRoot(child: Commander): Commander {
30-
return this.command(null, 'setRoot', arguments);
31-
}
32-
33-
static delay(lineNumber?: Number): Commander {
34-
return this.command(null, 'delay', arguments);
3526
}
3627

3728
private readonly key: string;
3829

3930
constructor(iArguments: IArguments) {
31+
Commander.objectCount++;
4032
const className = (<any>this).constructor.name;
4133
this.key = Commander.keyRandomizer.create();
4234
this.command(className, iArguments);
4335
}
4436

4537
destroy() {
4638
Commander.objectCount--;
47-
return this.command('destroy', arguments);
39+
this.command('destroy', arguments);
4840
}
4941

50-
command(method: string, iArguments: IArguments): this {
42+
command(method: string, iArguments: IArguments) {
5143
Commander.command(this.key, method, iArguments);
52-
return this;
53-
}
54-
55-
delay(lineNumber?: Number): this {
56-
Commander.delay(lineNumber);
57-
return this;
5844
}
5945

6046
toJSON() {

src/GraphTracer.ts

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,77 @@
11
import { LogTracer, Tracer } from './';
22

33
class GraphTracer extends Tracer {
4-
set(array2d?: any[][]): this {
5-
return this.command('set', arguments);
4+
set(array2d?: any[][]) {
5+
this.command('set', arguments);
66
}
77

8-
directed(isDirected?: boolean): this {
9-
return this.command('directed', arguments);
8+
directed(isDirected?: boolean) {
9+
this.command('directed', arguments);
10+
return this;
1011
}
1112

12-
weighted(isWeighted?: boolean): this {
13-
return this.command('weighted', arguments);
13+
weighted(isWeighted?: boolean) {
14+
this.command('weighted', arguments);
15+
return this;
1416
}
1517

16-
addNode(id: any, weight?: any, x?: number, y?: number, visitedCount?: number, selectedCount?: number): this {
17-
return this.command('addNode', arguments);
18+
layoutCircle() {
19+
this.command('layoutCircle', arguments);
20+
return this;
1821
}
1922

20-
updateNode(id: any, weight?: any, x?: number, y?: number, visitedCount?: number, selectedCount?: number): this {
21-
return this.command('updateNode', arguments);
23+
layoutTree(root?: any, sorted?: boolean) {
24+
this.command('layoutTree', arguments);
25+
return this;
2226
}
2327

24-
removeNode(id: any): this {
25-
return this.command('removeNode', arguments);
28+
layoutRandom() {
29+
this.command('layoutRandom', arguments);
30+
return this;
2631
}
2732

28-
addEdge(source: any, target: any, weight?: any, visitedCount?: number, selectedCount?: number): this {
29-
return this.command('addEdge', arguments);
33+
addNode(id: any, weight?: any, x?: number, y?: number, visitedCount?: number, selectedCount?: number) {
34+
this.command('addNode', arguments);
3035
}
3136

32-
updateEdge(source: any, target: any, weight?: any, visitedCount?: number, selectedCount?: number): this {
33-
return this.command('updateEdge', arguments);
37+
updateNode(id: any, weight?: any, x?: number, y?: number, visitedCount?: number, selectedCount?: number) {
38+
this.command('updateNode', arguments);
3439
}
3540

36-
removeEdge(source: any, target: any): this {
37-
return this.command('removeEdge', arguments);
41+
removeNode(id: any) {
42+
this.command('removeNode', arguments);
3843
}
3944

40-
layoutCircle() {
41-
return this.command('layoutCircle', arguments);
45+
addEdge(source: any, target: any, weight?: any, visitedCount?: number, selectedCount?: number) {
46+
this.command('addEdge', arguments);
4247
}
4348

44-
layoutTree(root?: any, sorted?: boolean) {
45-
return this.command('layoutTree', arguments);
49+
updateEdge(source: any, target: any, weight?: any, visitedCount?: number, selectedCount?: number) {
50+
this.command('updateEdge', arguments);
4651
}
4752

48-
layoutRandom() {
49-
return this.command('layoutRandom', arguments);
53+
removeEdge(source: any, target: any) {
54+
this.command('removeEdge', arguments);
5055
}
5156

5257
visit(target: any, source?: any, weight?: any) {
53-
return this.command('visit', arguments);
58+
this.command('visit', arguments);
5459
}
5560

5661
leave(target: any, source?: any, weight?: any) {
57-
return this.command('leave', arguments);
62+
this.command('leave', arguments);
5863
}
5964

6065
select(target: any, source?: any) {
61-
return this.command('select', arguments);
66+
this.command('select', arguments);
6267
}
6368

6469
deselect(target: any, source?: any) {
65-
return this.command('deselect', arguments);
70+
this.command('deselect', arguments);
6671
}
6772

6873
log(logTracer: LogTracer) {
69-
return this.command('log', arguments);
74+
this.command('log', arguments);
7075
}
7176
}
7277

src/Layout.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import { Commander } from './';
22

33
class Layout extends Commander {
4+
static setRoot(child: Commander) {
5+
this.command(null, 'setRoot', arguments);
6+
}
7+
48
constructor(children: [Commander]) {
59
super(arguments);
610
}
711

8-
add(child: Commander, index?: Number): this {
9-
return this.command('add', arguments);
12+
add(child: Commander, index?: Number) {
13+
this.command('add', arguments);
1014
}
1115

12-
remove(child: Commander): this {
13-
return this.command('remove', arguments);
16+
remove(child: Commander) {
17+
this.command('remove', arguments);
1418
}
1519

16-
removeAll(): this {
17-
return this.command('removeAll', arguments);
20+
removeAll() {
21+
this.command('removeAll', arguments);
1822
}
1923
}
2024

src/LogTracer.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { Tracer } from './';
22

33
class LogTracer extends Tracer {
4-
set(log?: string): this {
5-
return this.command('set', arguments);
4+
set(log?: string) {
5+
this.command('set', arguments);
66
}
77

8-
print(message: any): this {
9-
return this.command('print', arguments);
8+
print(message: any) {
9+
this.command('print', arguments);
1010
}
1111

12-
println(message: any): this {
13-
return this.command('println', arguments);
12+
println(message: any) {
13+
this.command('println', arguments);
1414
}
1515

16-
printf(format: string, ...args: any[]): this {
17-
return this.command('printf', arguments);
16+
printf(format: string, ...args: any[]) {
17+
this.command('printf', arguments);
1818
}
1919
}
2020

src/Tracer.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import { Commander } from './';
22

33
class Tracer extends Commander {
4+
static delay(lineNumber?: Number) {
5+
this.command(null, 'delay', arguments);
6+
}
7+
48
constructor(title?: string) {
59
super(arguments);
610
}
711

8-
set(): this {
9-
return this.command('set', arguments);
12+
set() {
13+
this.command('set', arguments);
1014
}
1115

12-
reset(): this {
13-
return this.command('reset', arguments);
16+
reset() {
17+
this.command('reset', arguments);
1418
}
1519
}
1620

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy