@@ -3,8 +3,6 @@ import valueCache from 'core/cache/value';
3
3
import { ICellFactoryProps } from 'dash-table/components/Table/props' ;
4
4
import { handleChange , handleClick , handleDoubleClick , handleOnMouseUp , handlePaste } from 'dash-table/handlers/cellEvents' ;
5
5
6
- type CacheArgs = [ Handler , number , number ] ;
7
-
8
6
export enum Handler {
9
7
Change = 'change' ,
10
8
Click = 'click' ,
@@ -13,32 +11,32 @@ export enum Handler {
13
11
Paste = 'paste'
14
12
}
15
13
16
- export type CacheFn = ( ...args : CacheArgs ) => Function ;
17
- export type HandlerFn = ( ...args : any [ ] ) => any ;
18
-
19
14
export default ( propsFn : ( ) => ICellFactoryProps ) => new EventHandler ( propsFn ) . get ;
20
15
21
16
class EventHandler {
22
17
constructor ( private readonly propsFn : ( ) => ICellFactoryProps ) {
23
18
24
19
}
25
20
26
- private readonly handlers = new Map < Handler , HandlerFn > ( [
27
- [ Handler . Change , handleChange . bind ( undefined , this . propsFn ) ] ,
28
- [ Handler . Click , handleClick . bind ( undefined , this . propsFn ) ] ,
29
- [ Handler . DoubleClick , handleDoubleClick . bind ( undefined , this . propsFn ) ] ,
30
- [ Handler . MouseUp , handleOnMouseUp . bind ( undefined , this . propsFn ) ] ,
31
- [ Handler . Paste , handlePaste . bind ( undefined , this . propsFn ) ]
32
- ] ) ;
33
-
34
21
private readonly cache = valueCache < [ Handler , number , number ] > ( ) ( (
35
22
handler : Handler ,
36
23
columnIndex : number ,
37
24
rowIndex : number
38
25
) => {
39
- let handlerFn = this . handlers . get ( handler ) ;
40
-
41
- return handlerFn && handlerFn . bind ( undefined , rowIndex , columnIndex ) ;
26
+ switch ( handler ) {
27
+ case Handler . Change :
28
+ return handleChange . bind ( undefined , this . propsFn , rowIndex , columnIndex ) ;
29
+ case Handler . Click :
30
+ return handleClick . bind ( undefined , this . propsFn , rowIndex , columnIndex ) ;
31
+ case Handler . DoubleClick :
32
+ return handleDoubleClick . bind ( undefined , this . propsFn , rowIndex , columnIndex ) ;
33
+ case Handler . MouseUp :
34
+ return handleOnMouseUp . bind ( undefined , this . propsFn , rowIndex , columnIndex ) ;
35
+ case Handler . Paste :
36
+ return handlePaste . bind ( undefined , this . propsFn , rowIndex , columnIndex ) ;
37
+ default :
38
+ throw new Error ( `unexpected handler ${ handler } ` ) ;
39
+ }
42
40
} ) ;
43
41
44
42
get = (
0 commit comments