File tree 7 files changed +8
-46
lines changed
nativescript-angular/value-accessors
7 files changed +8
-46
lines changed Original file line number Diff line number Diff line change 1
1
import { ControlValueAccessor } from "@angular/forms" ;
2
2
3
3
export class BaseValueAccessor < TView > implements ControlValueAccessor {
4
- constructor ( public view : TView ) { }
5
-
6
- onChange = ( _ ) => { } ;
7
4
private pendingChangeNotification : number = 0 ;
5
+ onChange = ( _ ) => { } ;
6
+ onTouched = ( ) => { } ;
7
+
8
+ constructor ( public view : TView ) { }
8
9
9
10
registerOnChange ( fn : ( _ : any ) => void ) : void {
10
11
this . onChange = ( arg ) => {
@@ -18,11 +19,7 @@ export class BaseValueAccessor<TView> implements ControlValueAccessor {
18
19
} ;
19
20
}
20
21
21
- writeValue ( _ : any ) {
22
- //
23
- }
22
+ registerOnTouched ( fn : ( ) => void ) : void { this . onTouched = fn ; }
24
23
25
- registerOnTouched ( _ : ( ) => void ) : void {
26
- //
27
- }
24
+ writeValue ( _ : any ) { }
28
25
}
Original file line number Diff line number Diff line change @@ -29,17 +29,11 @@ const CHECKED_VALUE_ACCESSOR = {
29
29
} ,
30
30
} )
31
31
export class CheckedValueAccessor extends BaseValueAccessor < Switch > { // tslint:disable-line:directive-class-suffix
32
- onChange = ( _ : any ) => { } ;
33
- onTouched = ( ) => { } ;
34
-
35
32
constructor ( elementRef : ElementRef ) {
36
33
super ( elementRef . nativeElement ) ;
37
34
}
38
35
39
36
writeValue ( value : any ) : void {
40
37
this . view . checked = value ;
41
38
}
42
-
43
- registerOnChange ( fn : ( _ : any ) => { } ) : void { this . onChange = fn ; }
44
- registerOnTouched ( fn : ( ) => void ) : void { this . onTouched = fn ; }
45
39
}
Original file line number Diff line number Diff line change @@ -30,17 +30,11 @@ const DATE_VALUE_ACCESSOR = {
30
30
} ,
31
31
} )
32
32
export class DateValueAccessor extends BaseValueAccessor < DatePicker > { // tslint:disable-line:directive-class-suffix
33
- onChange = ( _ : any ) => { } ;
34
- onTouched = ( ) => { } ;
35
-
36
33
constructor ( elementRef : ElementRef ) {
37
34
super ( elementRef . nativeElement ) ;
38
35
}
39
36
40
37
writeValue ( value : any ) : void {
41
38
this . view . date = value ;
42
39
}
43
-
44
- registerOnChange ( fn : ( _ : any ) => { } ) : void { this . onChange = fn ; }
45
- registerOnTouched ( fn : ( ) => void ) : void { this . onTouched = fn ; }
46
40
}
Original file line number Diff line number Diff line change @@ -29,17 +29,11 @@ const NUMBER_VALUE_ACCESSOR = {
29
29
} ,
30
30
} )
31
31
export class NumberValueAccessor extends BaseValueAccessor < Slider > { // tslint:disable-line:directive-class-suffix
32
- onChange = ( _ : any ) => { } ;
33
- onTouched = ( ) => { } ;
34
-
35
32
constructor ( elementRef : ElementRef ) {
36
33
super ( elementRef . nativeElement ) ;
37
34
}
38
35
39
36
writeValue ( value : any ) : void {
40
37
this . view . value = value ;
41
38
}
42
-
43
- registerOnChange ( fn : ( _ : any ) => { } ) : void { this . onChange = fn ; }
44
- registerOnTouched ( fn : ( ) => void ) : void { this . onTouched = fn ; }
45
39
}
Original file line number Diff line number Diff line change @@ -43,9 +43,6 @@ export type SelectableView = {selectedIndex: number} & View;
43
43
} ,
44
44
} )
45
45
export class SelectedIndexValueAccessor extends BaseValueAccessor < SelectableView > implements AfterViewInit { // tslint:disable-line:max-line-length directive-class-suffix
46
- onChange = ( _ : any ) => { } ;
47
- onTouched = ( ) => { } ;
48
-
49
46
constructor ( elementRef : ElementRef ) {
50
47
super ( elementRef . nativeElement ) ;
51
48
}
@@ -55,6 +52,7 @@ export class SelectedIndexValueAccessor extends BaseValueAccessor<SelectableView
55
52
56
53
writeValue ( value : any ) : void {
57
54
this . value = value ;
55
+
58
56
if ( this . viewInitialized ) {
59
57
this . view . selectedIndex = this . value ;
60
58
}
@@ -64,7 +62,4 @@ export class SelectedIndexValueAccessor extends BaseValueAccessor<SelectableView
64
62
this . viewInitialized = true ;
65
63
this . view . selectedIndex = this . value ;
66
64
}
67
-
68
- registerOnChange ( fn : ( _ : any ) => { } ) : void { this . onChange = fn ; }
69
- registerOnTouched ( fn : ( ) => void ) : void { this . onTouched = fn ; }
70
65
}
Original file line number Diff line number Diff line change @@ -39,21 +39,15 @@ export type TextView = {text: string} & View;
39
39
providers : [ TEXT_VALUE_ACCESSOR ] ,
40
40
host : {
41
41
"(touch)" : "onTouch()" ,
42
- "(textChange)" : "onChange(event.value)" ,
42
+ "(textChange)" : "onChange($ event.value)" ,
43
43
} ,
44
44
} )
45
45
export class TextValueAccessor extends BaseValueAccessor < TextView > { // tslint:disable-line:directive-class-suffix
46
- onChange = ( _ : any ) => { } ;
47
- onTouched = ( ) => { } ;
48
-
49
46
constructor ( elementRef : ElementRef ) {
50
47
super ( elementRef . nativeElement ) ;
51
48
}
52
49
53
50
writeValue ( value : any ) : void {
54
51
this . view . text = value ;
55
52
}
56
-
57
- registerOnChange ( fn : ( _ : any ) => { } ) : void { this . onChange = fn ; }
58
- registerOnTouched ( fn : ( ) => void ) : void { this . onTouched = fn ; }
59
53
}
Original file line number Diff line number Diff line change @@ -31,17 +31,11 @@ const TIME_VALUE_ACCESSOR = {
31
31
} ,
32
32
} )
33
33
export class TimeValueAccessor extends BaseValueAccessor < TimePicker > { // tslint:disable-line:directive-class-suffix
34
- onChange = ( _ : any ) => { } ;
35
- onTouched = ( ) => { } ;
36
-
37
34
constructor ( elementRef : ElementRef ) {
38
35
super ( elementRef . nativeElement ) ;
39
36
}
40
37
41
38
writeValue ( value : any ) : void {
42
39
this . view . time = value ;
43
40
}
44
-
45
- registerOnChange ( fn : ( _ : any ) => { } ) : void { this . onChange = fn ; }
46
- registerOnTouched ( fn : ( ) => void ) : void { this . onTouched = fn ; }
47
41
}
You can’t perform that action at this time.
0 commit comments