@@ -3,133 +3,17 @@ import { boundMethod } from 'autobind-decorator';
3
3
import { NAME_PLUGIN } from '@shared/constants' ;
4
4
5
5
import { RangeSliderOptions } from '../../globInterface' ;
6
- import Model from '../model/Model' ;
7
- import View from '../view/View' ;
8
-
9
- interface DataAttributesProps extends RangeSliderOptions {
10
- key : 'DataAttributes' ;
11
- }
6
+ import {
7
+ ControllerEventProps ,
8
+ DataAttributesProps ,
9
+ } from './controllerInterface' ;
12
10
13
- type SnapNumberProps = {
14
- key : 'SnapNumber' ;
15
- isResized : boolean ;
16
- snapNumber : number [ ] ;
17
- }
18
-
19
- type ClickMarkProps = {
20
- key : 'ClickMark' ;
21
- valueGrid : number ;
22
- } ;
23
-
24
- type CreateGridProps = {
25
- key : 'CreateGrid' ;
26
- valueMark : {
27
- value : number ;
28
- position : number ;
29
- } [ ] ;
30
- } ;
31
-
32
- type ClickBarProps = {
33
- key : 'ClickBar' ;
34
- clientXY : number ;
35
- } ;
36
-
37
- type BarDataProps = {
38
- key : 'BarData' ;
39
- bar : boolean | null ;
40
- } ;
41
-
42
- type ClickLineProps = {
43
- key : 'ClickLine' ;
44
- clientXY : number ;
45
- } ;
46
-
47
- type DisabledDataProps = {
48
- key : 'DisabledData' ;
49
- disabled : boolean | null ;
50
- } ;
51
-
52
- type ThemeDataProps = {
53
- key : 'ThemeData' ;
54
- theme : string | null ;
55
- } ;
56
-
57
- type OrientationDataProps = {
58
- key : 'OrientationData' ;
59
- orientation : string | null ;
60
- } ;
61
-
62
- type GridDataProps = {
63
- key : 'GridData' ;
64
- grid : boolean | null ;
65
- } ;
66
-
67
- type GridSnapDataProps = {
68
- key : 'GridSnapData' ;
69
- }
11
+ import {
12
+ ViewEventProps ,
13
+ } from '../view/viewInterface' ;
70
14
71
- type DotMoveProps = {
72
- key : 'DotMove' ;
73
- type : string | null ;
74
- position : number ;
75
- clientXY : number ;
76
- shiftXY : number ;
77
- } ;
78
-
79
- type DotDataProps = {
80
- key : 'DotData' ;
81
- type : string | null ;
82
- to : number | null ;
83
- from : number | null ;
84
- } ;
85
-
86
- type DotKeyDownProps = {
87
- key : 'DotKeyDown' ;
88
- keyRepeat : boolean ;
89
- keySign : string ;
90
- dot : string ;
91
- } ;
92
-
93
- type RangeDataProps = {
94
- key : 'RangeData' ;
95
- min : number ;
96
- max : number ;
97
- } ;
98
-
99
- type StartProps = {
100
- key : 'Start' ;
101
- } ;
102
-
103
- type HintsProps = {
104
- key ?: 'HintsData' ;
105
- type ?: string | null ;
106
- from ?: number | null ;
107
- to ?: number | null ;
108
- tipPrefix ?: string | null ;
109
- tipPostfix ?: string | null ;
110
- tipFromTo ?: boolean | null ;
111
- tipMinMax ?: boolean | null ;
112
- min ?: number | null ;
113
- max ?: number | null ;
114
- } ;
115
-
116
- type EventProps = HintsProps |
117
- StartProps |
118
- DotDataProps |
119
- DotKeyDownProps |
120
- RangeDataProps |
121
- DotMoveProps |
122
- GridSnapDataProps |
123
- GridDataProps |
124
- OrientationDataProps |
125
- ThemeDataProps |
126
- DisabledDataProps |
127
- ClickLineProps |
128
- BarDataProps |
129
- ClickBarProps |
130
- CreateGridProps |
131
- ClickMarkProps |
132
- SnapNumberProps ;
15
+ import Model from '../model/Model' ;
16
+ import View from '../view/View' ;
133
17
134
18
class Controller {
135
19
private isStarted = false ;
@@ -212,9 +96,18 @@ class Controller {
212
96
return true ;
213
97
}
214
98
215
- private static subscribe (
216
- talking : Model | View ,
217
- items : ( ( options : EventProps ) => boolean | Promise < boolean > ) [ ] ,
99
+ private static subscribeModel (
100
+ talking : Model ,
101
+ items : ( ( options : ControllerEventProps ) => boolean | Promise < boolean > ) [ ] ,
102
+ ) {
103
+ return items . forEach ( ( item : any ) => {
104
+ talking . subscribeObserver ( item ) ;
105
+ } ) ;
106
+ }
107
+
108
+ private static subscribeView (
109
+ talking : View ,
110
+ items : ( ( options : ViewEventProps ) => boolean ) [ ] ,
218
111
) {
219
112
return items . forEach ( ( item ) => {
220
113
talking . subscribeObserver ( item ) ;
@@ -240,7 +133,7 @@ class Controller {
240
133
this . handleGridCreation ,
241
134
] ;
242
135
243
- Controller . subscribe ( this . model , handlesModel ) ;
136
+ Controller . subscribeModel ( this . model , handlesModel ) ;
244
137
245
138
const handlesView = [
246
139
this . handleDotMove ,
@@ -252,13 +145,13 @@ class Controller {
252
145
this . handleDataAttributes ,
253
146
] ;
254
147
255
- Controller . subscribe ( this . view , handlesView ) ;
148
+ Controller . subscribeView ( this . view , handlesView ) ;
256
149
257
150
return true ;
258
151
}
259
152
260
153
@boundMethod
261
- private handleStart ( options : StartProps ) {
154
+ private handleStart ( options : ControllerEventProps ) {
262
155
const { key } = options ;
263
156
const isStarted = key !== 'Start' ;
264
157
@@ -291,7 +184,7 @@ class Controller {
291
184
}
292
185
293
186
@boundMethod
294
- private handleRangeData ( options : RangeDataProps ) {
187
+ private handleRangeData ( options : ControllerEventProps ) {
295
188
const { key } = options ;
296
189
if ( key !== 'RangeData' ) {
297
190
return false ;
@@ -321,7 +214,7 @@ class Controller {
321
214
}
322
215
323
216
@boundMethod
324
- private handleDotKeyDown ( options : DotKeyDownProps ) {
217
+ private handleDotKeyDown ( options : ViewEventProps ) {
325
218
const { key } = options ;
326
219
const isDotKeyDown = key !== 'DotKeyDown' ;
327
220
@@ -341,7 +234,7 @@ class Controller {
341
234
}
342
235
343
236
@boundMethod
344
- private handleDotData ( options : DotDataProps ) {
237
+ private handleDotData ( options : ControllerEventProps ) {
345
238
const { key } = options ;
346
239
if ( key !== 'DotData' ) {
347
240
return false ;
@@ -387,7 +280,7 @@ class Controller {
387
280
}
388
281
389
282
@boundMethod
390
- private handleDotMove ( options : DotMoveProps ) {
283
+ private handleDotMove ( options : ViewEventProps ) {
391
284
const { key } = options ;
392
285
const isDotMove = key !== 'DotMove' ;
393
286
@@ -409,7 +302,7 @@ class Controller {
409
302
}
410
303
411
304
@boundMethod
412
- private handleGridSnapData ( options : GridSnapDataProps ) {
305
+ private handleGridSnapData ( options : ControllerEventProps ) {
413
306
const { key } = options ;
414
307
const isGridSnapData = key !== 'GridSnapData' ;
415
308
@@ -422,7 +315,7 @@ class Controller {
422
315
}
423
316
424
317
@boundMethod
425
- private handleGridData ( options : GridDataProps ) {
318
+ private handleGridData ( options : ControllerEventProps ) {
426
319
const { key } = options ;
427
320
428
321
if ( key !== 'GridData' ) {
@@ -447,7 +340,7 @@ class Controller {
447
340
}
448
341
449
342
@boundMethod
450
- private async handleOrientationData ( options : OrientationDataProps ) {
343
+ private async handleOrientationData ( options : ControllerEventProps ) {
451
344
const { key } = options ;
452
345
if ( key !== 'OrientationData' ) {
453
346
return false ;
@@ -472,7 +365,7 @@ class Controller {
472
365
}
473
366
474
367
@boundMethod
475
- private handleThemeData ( options : ThemeDataProps ) {
368
+ private handleThemeData ( options : ControllerEventProps ) {
476
369
const { key } = options ;
477
370
const isThemeData = key !== 'ThemeData' ;
478
371
@@ -485,7 +378,7 @@ class Controller {
485
378
}
486
379
487
380
@boundMethod
488
- private handleHintsData ( options : HintsProps ) {
381
+ private handleHintsData ( options : ControllerEventProps ) {
489
382
const { key } = options ;
490
383
if ( key !== 'HintsData' ) {
491
384
return false ;
@@ -553,7 +446,7 @@ class Controller {
553
446
}
554
447
555
448
@boundMethod
556
- private handleDisabledData ( options : DisabledDataProps ) {
449
+ private handleDisabledData ( options : ControllerEventProps ) {
557
450
const { key } = options ;
558
451
const isDisabledData = key !== 'DisabledData' ;
559
452
@@ -568,7 +461,7 @@ class Controller {
568
461
}
569
462
570
463
@boundMethod
571
- private handleLineClick ( options : ClickLineProps ) {
464
+ private handleLineClick ( options : ViewEventProps ) {
572
465
const { key } = options ;
573
466
const isClickLine = key !== 'ClickLine' ;
574
467
@@ -587,7 +480,7 @@ class Controller {
587
480
}
588
481
589
482
@boundMethod
590
- private handleBarData ( options : BarDataProps ) {
483
+ private handleBarData ( options : ControllerEventProps ) {
591
484
const { key } = options ;
592
485
if ( key !== 'BarData' ) {
593
486
return false ;
@@ -604,7 +497,7 @@ class Controller {
604
497
}
605
498
606
499
@boundMethod
607
- private handleBarClick ( options : ClickBarProps ) {
500
+ private handleBarClick ( options : ViewEventProps ) {
608
501
const { key } = options ;
609
502
const isClickBar = key !== 'ClickBar' ;
610
503
@@ -624,7 +517,7 @@ class Controller {
624
517
}
625
518
626
519
@boundMethod
627
- private handleGridCreation ( options : CreateGridProps ) {
520
+ private handleGridCreation ( options : ControllerEventProps ) {
628
521
const { key } = options ;
629
522
const isCreateGrid = key !== 'CreateGrid' ;
630
523
@@ -637,7 +530,7 @@ class Controller {
637
530
}
638
531
639
532
@boundMethod
640
- private handleMarkClick ( options : ClickMarkProps ) {
533
+ private handleMarkClick ( options : ViewEventProps ) {
641
534
const { key } = options ;
642
535
const isClickMark = key !== 'ClickMark' ;
643
536
@@ -653,7 +546,7 @@ class Controller {
653
546
}
654
547
655
548
@boundMethod
656
- private handleSnapNumber ( options : SnapNumberProps ) {
549
+ private handleSnapNumber ( options : ViewEventProps ) {
657
550
const { key } = options ;
658
551
const isSnapNumber = key !== 'SnapNumber' ;
659
552
0 commit comments