Skip to content

Commit 34cd195

Browse files
authored
Added constructor to SwitchManager to deal with error about exported classes needing a constructor
1 parent 77f63c0 commit 34cd195

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

classes/switchcontext.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22
namespace switchcase {
33
export class SwitchContext {
44
private Cases: { Match: any, Handler: () => void, IsDefault?: boolean }[] = [];
5+
private Name: string;
56
private Value: any;
67
public IsValueSet: boolean;
78

9+
constructor(name: string, value: any) {
10+
this.Value = value;
11+
this.Name = name;
12+
}
13+
14+
15+
816
addCase(match: any, handler: () => void): void {
917
this.Cases.push({ Match: match, Handler: handler });
1018
}

classes/switchmanager.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,22 @@ namespace switchcase {
44
export class SwitchManager {
55
private Switches: { [Name: string]: SwitchContext } = {};
66

7+
constructor() {
8+
this.create("default");
9+
}
10+
711
create(name: string): SwitchContext {
8-
const ctx = new SwitchContext();
12+
const ctx = new SwitchContext(name, {});
913
this.Switches[name] = ctx;
1014
return ctx;
1115
}
1216

17+
createWithValue(name: string, value: any): SwitchContext {
18+
let cxt = this.create(name);
19+
cxt.setValue(value);
20+
return cxt;
21+
}
22+
1323
get(name: string): SwitchContext {
1424
return this.Switches[name];
1525
}

0 commit comments

Comments
 (0)