import { ESLMediaQuery } from './esl-media-query' ; type PayloadParser < T > = ( val : string ) => T | undefined ; author Yuliya Adamskaya *
 * Helper class to wrap  ESLMediaQuery with the payload value
 *  see ESLMediaQuery see ESLMediaRuleList export class ESLMediaRule < T > { private readonly _query : ESLMediaQuery ; private readonly _payload : T ; private readonly _default : boolean ; constructor ( payload , query = '' ) { this . _query = ESLMediaQuery . for ( query ) ; this . _default = ! query ; this . _payload = payload ; } public toString ( ) { return `${ this . _query } => ${ this . _payload }` ; } /** Subscribes on inner  ESLMediaQuery changes  public addListener ( listener ) { this . _query . addListener ( listener ) ; } /** Unsubscribes from inner  ESLMediaQuery changes  public removeListener ( listener ) { this . _query . removeListener ( listener ) ; } /** Check if the inner  ESLMediaQuery is matching current device configuration  public get matches ( ) : boolean { return this . _query . matches ; } returns public get payload ( ) : T { return this . _payload ; } see ESLMediaRuleList public get default ( ) : boolean { return this . _default ; } /** Parse the rule string to the  ESLMediaRule instance  public static parse < U > ( lex , parser ) { const parts = lex . split ( '=>' ) ; const query = parts . length === 2 ? parts [ 0 ] : '' ; const payload = parts . length === 2 ? parts [ 1 ] : parts [ 0 ] ; const payloadValue = parser ( payload . trim ( ) ) ; if ( typeof payloadValue === 'undefined' ) return undefined ; return new ESLMediaRule < U > ( payloadValue , query . trim ( ) ) ; } /** Shortcut to create always active  ESLMediaRule with passed value  public static all < U > ( payload ) { return new ESLMediaRule < U > ( payload , 'all' ) ; } /** Shortcut to create condition-less  ESLMediaRule public static default < U > ( payload ) { return new ESLMediaRule < U > ( payload ) ; } /** Shortcut to create always inactive  ESLMediaRule public static empty ( ) { return new ESLMediaRule ( undefined , 'all' ) ; } }