1
1
import { 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' ;
3
3
import { map , switchMap , tap , shareReplay , distinctUntilChanged , filter , groupBy , mergeMap , scan , withLatestFrom , startWith , debounceTime } from 'rxjs/operators' ;
4
4
import { FirebaseAppConfig , FirebaseOptions , ɵlazySDKProxy , FIREBASE_OPTIONS , FIREBASE_APP_NAME } from '@angular/fire' ;
5
5
import { remoteConfig } from 'firebase/app' ;
@@ -65,9 +65,9 @@ export class AngularFireRemoteConfig {
65
65
66
66
readonly changes : Observable < Parameter > ;
67
67
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 > } ;
71
71
72
72
constructor (
73
73
@Inject ( FIREBASE_OPTIONS ) options :FirebaseOptions ,
@@ -154,7 +154,7 @@ const scanToParametersArray = (remoteConfig: Observable<remoteConfig.RemoteConfi
154
154
const AS_TO_FN = { 'strings' : 'asString' , 'numbers' : 'asNumber' , 'booleans' : 'asBoolean' } ;
155
155
const PROXY_DEFAULTS = { 'numbers' : 0 , 'booleans' : false , 'strings' : undefined } ;
156
156
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 => {
158
158
let timedOut = false ;
159
159
// TODO use scheduler task rather than settimeout
160
160
const timeout = setTimeout ( ( ) => {
@@ -177,30 +177,44 @@ const typedMethod = (it:any) => {
177
177
}
178
178
} ;
179
179
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 } > ;
184
184
export 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' ) {
186
186
return pipe (
187
187
// 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
+ ) ,
189
196
debounceTime ( 1 ) ,
190
197
budget ( 10 ) ,
191
198
distinctUntilChanged ( ( a , b ) => JSON . stringify ( a ) === JSON . stringify ( b ) )
192
199
) ;
193
200
} ;
194
201
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 } > ;
199
206
export 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' ) {
201
208
return pipe (
202
209
// 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
+ ) ) ,
204
218
distinctUntilChanged ( ( a , b ) => JSON . stringify ( a ) === JSON . stringify ( b ) )
205
219
) ;
206
220
} ;
0 commit comments