11import { Injectable , Inject , Optional , NgZone , InjectionToken , PLATFORM_ID } from '@angular/core' ;
2- import { Observable , concat , of , pipe , OperatorFunction } from 'rxjs' ;
2+ import { Observable , concat , of , pipe , OperatorFunction , MonoTypeOperatorFunction } from 'rxjs' ;
33import { map , switchMap , tap , shareReplay , distinctUntilChanged , filter , groupBy , mergeMap , scan , withLatestFrom , startWith , debounceTime } from 'rxjs/operators' ;
44import { FirebaseAppConfig , FirebaseOptions , ɵlazySDKProxy , FIREBASE_OPTIONS , FIREBASE_APP_NAME } from '@angular/fire' ;
55import { remoteConfig } from 'firebase/app' ;
@@ -65,9 +65,9 @@ export class AngularFireRemoteConfig {
6565
6666 readonly changes : Observable < Parameter > ;
6767 readonly parameters : Observable < Parameter [ ] > ;
68- readonly numbers : Observable < { [ key :string ] : number } > & { [ key :string ] : Observable < number > } ;
69- readonly booleans : Observable < { [ key :string ] : boolean } > & { [ key :string ] : Observable < boolean > } ;
70- readonly strings : Observable < { [ key :string ] : string } > & { [ key :string ] : Observable < string | undefined > } ;
68+ readonly numbers : Observable < { [ key :string ] : number | undefined } > & { [ key :string ] : Observable < number > } ;
69+ readonly booleans : Observable < { [ key :string ] : boolean | undefined } > & { [ key :string ] : Observable < boolean > } ;
70+ readonly strings : Observable < { [ key :string ] : string | undefined } > & { [ key :string ] : Observable < string | undefined > } ;
7171
7272 constructor (
7373 @Inject ( FIREBASE_OPTIONS ) options :FirebaseOptions ,
@@ -154,7 +154,7 @@ const scanToParametersArray = (remoteConfig: Observable<remoteConfig.RemoteConfi
154154const AS_TO_FN = { 'strings' : 'asString' , 'numbers' : 'asNumber' , 'booleans' : 'asBoolean' } ;
155155const PROXY_DEFAULTS = { 'numbers' : 0 , 'booleans' : false , 'strings' : undefined } ;
156156
157- export const budget = ( interval : number ) => < T > ( source : Observable < T > ) => new Observable < T > ( observer => {
157+ export const budget = < T > ( interval : number ) : MonoTypeOperatorFunction < T > => ( source : Observable < T > ) => new Observable < T > ( observer => {
158158 let timedOut = false ;
159159 // TODO use scheduler task rather than settimeout
160160 const timeout = setTimeout ( ( ) => {
@@ -177,30 +177,44 @@ const typedMethod = (it:any) => {
177177 }
178178} ;
179179
180- export function scanToObject ( ) : OperatorFunction < Parameter , { [ key :string ] : string } > ;
181- export function scanToObject ( as : 'numbers' ) : OperatorFunction < Parameter , { [ key :string ] : number } > ;
182- export function scanToObject ( as : 'booleans' ) : OperatorFunction < Parameter , { [ key :string ] : boolean } > ;
183- export function scanToObject ( as : 'strings' ) : OperatorFunction < Parameter , { [ key :string ] : string } > ;
180+ export function scanToObject ( ) : OperatorFunction < Parameter , { [ key :string ] : string | undefined } > ;
181+ export function scanToObject ( to : 'numbers' ) : OperatorFunction < Parameter , { [ key :string ] : number | undefined } > ;
182+ export function scanToObject ( to : 'booleans' ) : OperatorFunction < Parameter , { [ key :string ] : boolean | undefined } > ;
183+ export function scanToObject ( to : 'strings' ) : OperatorFunction < Parameter , { [ key :string ] : string | undefined } > ;
184184export function scanToObject < T extends ConfigTemplate > ( template : T ) : OperatorFunction < Parameter , T & { [ key :string ] : string | undefined } > ;
185- export function scanToObject ( as : 'numbers' | 'booleans' | 'strings' | ConfigTemplate = 'strings' ) {
185+ export function scanToObject < T extends ConfigTemplate > ( to : 'numbers' | 'booleans' | 'strings' | T = 'strings' ) {
186186 return pipe (
187187 // TODO cleanup
188- scan ( ( c , p : Parameter ) => ( { ...c , [ p . key ] : typeof as === 'object' ? p [ typedMethod ( as [ p . key ] ) ] ( ) : p [ AS_TO_FN [ as ] ] ( ) } ) , typeof as === 'object' ? as : { } as { [ key :string ] : number | boolean | string } ) ,
188+ scan (
189+ ( c , p : Parameter ) => ( { ...c , [ p . key ] : typeof to === 'object' ?
190+ p [ typedMethod ( to [ p . key ] ) ] ( ) :
191+ p [ AS_TO_FN [ to ] ] ( ) } ) ,
192+ typeof to === 'object' ?
193+ to as T & { [ key :string ] : string | undefined } :
194+ { } as { [ key :string ] : number | boolean | string }
195+ ) ,
189196 debounceTime ( 1 ) ,
190197 budget ( 10 ) ,
191198 distinctUntilChanged ( ( a , b ) => JSON . stringify ( a ) === JSON . stringify ( b ) )
192199 ) ;
193200} ;
194201
195- export function mapToObject ( ) : OperatorFunction < Parameter [ ] , { [ key :string ] : string } > ;
196- export function mapToObject ( as : 'numbers' ) : OperatorFunction < Parameter [ ] , { [ key :string ] : number } > ;
197- export function mapToObject ( as : 'booleans' ) : OperatorFunction < Parameter [ ] , { [ key :string ] : boolean } > ;
198- export function mapToObject ( as : 'strings' ) : OperatorFunction < Parameter [ ] , { [ key :string ] : string } > ;
202+ export function mapToObject ( ) : OperatorFunction < Parameter [ ] , { [ key :string ] : string | undefined } > ;
203+ export function mapToObject ( to : 'numbers' ) : OperatorFunction < Parameter [ ] , { [ key :string ] : number | undefined } > ;
204+ export function mapToObject ( to : 'booleans' ) : OperatorFunction < Parameter [ ] , { [ key :string ] : boolean | undefined } > ;
205+ export function mapToObject ( to : 'strings' ) : OperatorFunction < Parameter [ ] , { [ key :string ] : string | undefined } > ;
199206export function mapToObject < T extends ConfigTemplate > ( template : T ) : OperatorFunction < Parameter [ ] , T & { [ key :string ] : string | undefined } > ;
200- export function mapToObject ( as : 'numbers' | 'booleans' | 'strings' | ConfigTemplate = 'strings' ) {
207+ export function mapToObject < T extends ConfigTemplate > ( to : 'numbers' | 'booleans' | 'strings' | T = 'strings' ) {
201208 return pipe (
202209 // TODO this is getting a little long, cleanup
203- map ( ( params : Parameter [ ] ) => params . reduce ( ( c , p ) => ( { ...c , [ p . key ] : typeof as === 'object' ? p [ typedMethod ( as [ p . key ] ) ] ( ) : p [ AS_TO_FN [ as ] ] ( ) } ) , typeof as === 'object' ? as : { } as { [ key :string ] : number | boolean | string } ) ) ,
210+ map ( ( params : Parameter [ ] ) => params . reduce (
211+ ( c , p ) => ( { ...c , [ p . key ] : typeof to === 'object' ?
212+ p [ typedMethod ( to [ p . key ] ) ] ( ) :
213+ p [ AS_TO_FN [ to ] ] ( ) } ) ,
214+ typeof to === 'object' ?
215+ to as T & { [ key :string ] : string | undefined } :
216+ { } as { [ key :string ] : number | boolean | string }
217+ ) ) ,
204218 distinctUntilChanged ( ( a , b ) => JSON . stringify ( a ) === JSON . stringify ( b ) )
205219 ) ;
206220} ;
0 commit comments