1
- /**
2
- * Adapted BaseFxDirective abtract class version so it can be used via composition.
3
- *
4
- * @see BaseFxDirective
5
- */
6
1
import { BaseFxDirective } from './base' ;
7
2
import { ResponsiveActivation } from './../responsive/responsive-activation' ;
8
3
import { MediaQuerySubscriber } from '../../media-query/media-change' ;
9
4
5
+ /**
6
+ * Adapter to the BaseFxDirective abstract class so it can be used via composition.
7
+ * @see BaseFxDirective
8
+ */
10
9
export class BaseFxDirectiveAdapter extends BaseFxDirective {
11
10
get inputMap ( ) {
12
11
return this . _inputMap ;
13
12
}
14
13
14
+ /**
15
+ * @see BaseFxDirective._mqActivation
16
+ */
17
+ get mqActivation ( ) : ResponsiveActivation {
18
+ return this . _mqActivation ;
19
+ }
20
+ /**
21
+ * @see BaseFxDirective._queryInput
22
+ */
23
+ queryInput ( key ) {
24
+ return this . _queryInput ( key ) ;
25
+ }
26
+
15
27
/**
16
28
* Save the property value.
17
29
*/
18
- cacheInput ( key ?: string , source ?: any ) {
19
- if ( Array . isArray ( source ) ) {
30
+ cacheInput ( key ?: string , source ?: any , cacheRaw = false ) {
31
+ if ( cacheRaw ) {
32
+ this . _cacheInputRaw ( key , source ) ;
33
+ } else if ( Array . isArray ( source ) ) {
20
34
this . _cacheInputArray ( key , source ) ;
21
35
} else if ( typeof source === 'object' ) {
22
36
this . _cacheInputObject ( key , source ) ;
23
37
} else if ( typeof source === 'string' ) {
24
38
this . _cacheInputString ( key , source ) ;
25
39
} else {
26
- throw new Error ( 'Invalid class value provided' ) ;
40
+ throw new Error ( 'Invalid class value provided. Did you want to cache the raw value? ' ) ;
27
41
}
28
42
}
29
43
30
- _cacheInputRaw ( key ?: string , source ?: any ) {
44
+ /**
45
+ * @see BaseFxDirective._listenForMediaQueryChanges
46
+ */
47
+ listenForMediaQueryChanges ( key : string ,
48
+ defaultValue : any ,
49
+ onMediaQueryChange : MediaQuerySubscriber ) : ResponsiveActivation {
50
+ return this . _listenForMediaQueryChanges ( key , defaultValue , onMediaQueryChange ) ;
51
+ }
52
+
53
+ // ************************************************************
54
+ // Protected Methods
55
+ // ************************************************************
56
+
57
+ /**
58
+ * No implicit transforms of the source.
59
+ * Required when caching values expected later for KeyValueDiffers
60
+ */
61
+ protected _cacheInputRaw ( key ?: string , source ?: any ) {
31
62
this . _inputMap [ key ] = source ;
32
63
}
33
64
34
65
/**
35
66
* Save the property value for Array values.
36
67
*/
37
- _cacheInputArray ( key ?: string , source ?: boolean [ ] ) {
68
+ protected _cacheInputArray ( key ?: string , source ?: boolean [ ] ) {
38
69
this . _inputMap [ key ] = source . join ( ' ' ) ;
39
70
}
40
71
41
72
/**
42
73
* Save the property value for key/value pair values.
43
74
*/
44
- _cacheInputObject ( key ?: string , source ?: { [ key : string ] : boolean } ) {
75
+ protected _cacheInputObject ( key ?: string , source ?: { [ key : string ] : boolean } ) {
45
76
let classes = [ ] ;
46
77
for ( let prop in source ) {
47
78
if ( ! ! source [ prop ] ) {
@@ -54,30 +85,7 @@ export class BaseFxDirectiveAdapter extends BaseFxDirective {
54
85
/**
55
86
* Save the property value for string values.
56
87
*/
57
- _cacheInputString ( key ?: string , source ?: string ) {
88
+ protected _cacheInputString ( key ?: string , source ?: string ) {
58
89
this . _inputMap [ key ] = source ;
59
90
}
60
-
61
- /**
62
- * @see BaseFxDirective._listenForMediaQueryChanges
63
- */
64
- listenForMediaQueryChanges ( key : string ,
65
- defaultValue : any ,
66
- onMediaQueryChange : MediaQuerySubscriber ) : ResponsiveActivation {
67
- return this . _listenForMediaQueryChanges ( key , defaultValue , onMediaQueryChange ) ;
68
- }
69
-
70
- /**
71
- * @see BaseFxDirective._queryInput
72
- */
73
- queryInput ( key ) {
74
- return this . _queryInput ( key ) ;
75
- }
76
-
77
- /**
78
- * @see BaseFxDirective._mqActivation
79
- */
80
- get mqActivation ( ) : ResponsiveActivation {
81
- return this . _mqActivation ;
82
- }
83
91
}
0 commit comments