File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 22namespace 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 }
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments