Skip to content

Commit 5394724

Browse files
committed
Enable method chaining for static methods as well
1 parent 1998c19 commit 5394724

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Diff for: package.json

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

Diff for: src/Commander.ts

+6-5
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): void {
17+
static command(key: string | null, method: string, iArguments: IArguments): Commander {
1818
const args = Array.from(iArguments);
1919
this.commands.push({
2020
key,
@@ -23,14 +23,15 @@ 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);
2627
}
2728

28-
static setRoot(child: Commander) {
29-
this.command(null, 'setRoot', arguments);
29+
static setRoot(child: Commander): Commander {
30+
return this.command(null, 'setRoot', arguments);
3031
}
3132

32-
static delay(lineNumber?: Number) {
33-
this.command(null, 'delay', arguments);
33+
static delay(lineNumber?: Number): Commander {
34+
return this.command(null, 'delay', arguments);
3435
}
3536

3637
private readonly key: string;

0 commit comments

Comments
 (0)