This repository was archived by the owner on Aug 25, 2020. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,8 +11,12 @@ export interface StyleReactiveDef {
1111 ( state : any ) : StyleDef ;
1212}
1313
14+ export interface WrappedStyleDef {
15+ ( ) : StyleDef ;
16+ }
17+
1418export interface PickStyleDef {
15- [ key : string ] : StyleDef ;
19+ [ key : string ] : StyleDef | WrappedStyleDef ;
1620}
1721
1822export type DirectiveSelector = [ string , StateSetter ] ;
Original file line number Diff line number Diff line change 11import { Injectable } from '@angular/core' ;
2- import { PickStyleDef , StyleDef } from './meta/def' ;
2+ import { PickStyleDef , StyleDef , WrappedStyleDef } from './meta/def' ;
3+ import { isFunction } from './utils/is-function' ;
34import { mergeDeepAll } from './utils/merge-deep' ;
45
56@Injectable ( )
@@ -13,17 +14,25 @@ export class StylerDefService {
1314
1415 pick ( state : string , styles : PickStyleDef , def : string | null = null ) : StyleDef {
1516 if ( state ) {
16- return styles [ state ] ;
17+ return this . unwrap ( styles [ state ] ) ;
1718 } else if ( def !== null ) {
18- return styles [ def ] ;
19+ return this . unwrap ( styles [ def ] ) ;
1920 } else {
2021 return { } ;
2122 }
2223 }
2324
2425 toggle ( state : boolean , styles : StyleDef , falseStyles ?: StyleDef ) : StyleDef {
2526 return state
26- ? styles
27- : falseStyles || { } ;
27+ ? this . unwrap ( styles )
28+ : this . unwrap ( falseStyles || { } ) ;
29+ }
30+
31+ unwrap ( raw : StyleDef | WrappedStyleDef ) : StyleDef {
32+ if ( isFunction ( raw ) ) {
33+ return raw ( ) ;
34+ } else {
35+ return raw ;
36+ }
2837 }
2938}
Original file line number Diff line number Diff line change 1+ export function isFunction ( x : any ) : x is Function {
2+ return x !== null && typeof x === 'function' ;
3+ }
You can’t perform that action at this time.
0 commit comments