1- /**
2- * Adapted BaseFxDirective abtract class version so it can be used via composition.
3- *
4- * @see BaseFxDirective
5- */
61import { BaseFxDirective } from './base' ;
72import { ResponsiveActivation } from './../responsive/responsive-activation' ;
83import { MediaQuerySubscriber } from '../../media-query/media-change' ;
94
5+ /**
6+ * Adapter to the BaseFxDirective abstract class so it can be used via composition.
7+ * @see BaseFxDirective
8+ */
109export class BaseFxDirectiveAdapter extends BaseFxDirective {
1110 get inputMap ( ) {
1211 return this . _inputMap ;
1312 }
1413
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+
1527 /**
1628 * Save the property value.
1729 */
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 ) ) {
2034 this . _cacheInputArray ( key , source ) ;
2135 } else if ( typeof source === 'object' ) {
2236 this . _cacheInputObject ( key , source ) ;
2337 } else if ( typeof source === 'string' ) {
2438 this . _cacheInputString ( key , source ) ;
2539 } 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? ' ) ;
2741 }
2842 }
2943
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 ) {
3162 this . _inputMap [ key ] = source ;
3263 }
3364
3465 /**
3566 * Save the property value for Array values.
3667 */
37- _cacheInputArray ( key ?: string , source ?: boolean [ ] ) {
68+ protected _cacheInputArray ( key ?: string , source ?: boolean [ ] ) {
3869 this . _inputMap [ key ] = source . join ( ' ' ) ;
3970 }
4071
4172 /**
4273 * Save the property value for key/value pair values.
4374 */
44- _cacheInputObject ( key ?: string , source ?: { [ key : string ] : boolean } ) {
75+ protected _cacheInputObject ( key ?: string , source ?: { [ key : string ] : boolean } ) {
4576 let classes = [ ] ;
4677 for ( let prop in source ) {
4778 if ( ! ! source [ prop ] ) {
@@ -54,30 +85,7 @@ export class BaseFxDirectiveAdapter extends BaseFxDirective {
5485 /**
5586 * Save the property value for string values.
5687 */
57- _cacheInputString ( key ?: string , source ?: string ) {
88+ protected _cacheInputString ( key ?: string , source ?: string ) {
5889 this . _inputMap [ key ] = source ;
5990 }
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- }
8391}
0 commit comments