@@ -12,7 +12,6 @@ import {
12
12
shareReplay ,
13
13
startWith ,
14
14
switchMap ,
15
- tap ,
16
15
withLatestFrom
17
16
} from 'rxjs/operators' ;
18
17
import {
@@ -27,9 +26,16 @@ import {
27
26
ɵPromiseProxy ,
28
27
ɵapplyMixins
29
28
} from '@angular/fire' ;
30
- import { isPlatformBrowser } from '@angular/common' ;
31
- import firebase from 'firebase/app' ;
32
- import { Settings } from './interfaces' ;
29
+ import {
30
+ RemoteConfig ,
31
+ ValueType ,
32
+ getRemoteConfig ,
33
+ activate ,
34
+ fetchAndActivate ,
35
+ getAll ,
36
+ ensureInitialized
37
+ } from 'firebase/remote-config' ;
38
+ import { Settings , ValueSource } from './interfaces' ;
33
39
import { proxyPolyfillCompat } from './base' ;
34
40
import { ɵfetchInstance } from '@angular/fire' ;
35
41
@@ -40,7 +46,7 @@ export interface ConfigTemplate {
40
46
export const SETTINGS = new InjectionToken < Settings > ( 'angularfire2.remoteConfig.settings' ) ;
41
47
export const DEFAULTS = new InjectionToken < ConfigTemplate > ( 'angularfire2.remoteConfig.defaultConfig' ) ;
42
48
43
- export interface AngularFireRemoteConfig extends ɵPromiseProxy < firebase . remoteConfig . RemoteConfig > {
49
+ export interface AngularFireRemoteConfig extends ɵPromiseProxy < RemoteConfig > {
44
50
}
45
51
46
52
const AS_TO_FN = { strings : 'asString' , numbers : 'asNumber' , booleans : 'asBoolean' } ;
@@ -58,7 +64,7 @@ const proxyAll = (observable: Observable<Parameter[]>, as: 'numbers' | 'booleans
58
64
) as any ;
59
65
60
66
// TODO export as implements Partial<...> so minor doesn't break us
61
- export class Value implements firebase . remoteConfig . Value {
67
+ export class Value implements ValueType {
62
68
asBoolean ( ) {
63
69
return [ '1' , 'true' , 't' , 'y' , 'yes' , 'on' ] . indexOf ( this . _value . toLowerCase ( ) ) > - 1 ;
64
70
}
@@ -76,13 +82,13 @@ export class Value implements firebase.remoteConfig.Value {
76
82
}
77
83
78
84
// tslint:disable-next-line:variable-name
79
- constructor ( public _source : firebase . remoteConfig . ValueSource , public _value : string ) {
85
+ constructor ( public _source : ValueSource , public _value : string ) {
80
86
}
81
87
}
82
88
83
89
// SEMVER use ConstructorParameters when we can support Typescript 3.6
84
90
export class Parameter extends Value {
85
- constructor ( public key : string , public fetchTimeMillis : number , source : firebase . remoteConfig . ValueSource , value : string ) {
91
+ constructor ( public key : string , public fetchTimeMillis : number , source : ValueSource , value : string ) {
86
92
super ( source , value ) ;
87
93
}
88
94
}
@@ -103,8 +109,8 @@ export const filterFresh = (howRecentInMillis: number) => filterTest(p => p.fetc
103
109
// on the Parameter. Also if it doesn't come from the server it won't emit again in .changes, due to the distinctUntilChanged,
104
110
// which we can simplify to === rather than deep comparison
105
111
const scanToParametersArray = (
106
- remoteConfig : Observable < firebase . remoteConfig . RemoteConfig | undefined >
107
- ) : OperatorFunction < { [ key : string ] : firebase . remoteConfig . Value } , Parameter [ ] > => pipe (
112
+ remoteConfig : Observable < RemoteConfig | undefined >
113
+ ) : OperatorFunction < { [ key : string ] : ValueType } , Parameter [ ] > => pipe (
108
114
withLatestFrom ( remoteConfig ) ,
109
115
scan ( ( existing , [ all , rc ] ) => {
110
116
// SEMVER use "new Set" to unique once we're only targeting es6
@@ -146,12 +152,12 @@ export class AngularFireRemoteConfig {
146
152
147
153
const remoteConfig$ = of ( undefined ) . pipe (
148
154
observeOn ( schedulers . outsideAngular ) ,
149
- switchMap ( ( ) => isPlatformBrowser ( platformId ) ? import ( 'firebase/remote-config' ) : EMPTY ) ,
150
- switchMap ( ( ) => import ( '@firebase/remote-config' ) ) ,
151
- tap ( rc => rc . registerRemoteConfig && rc . registerRemoteConfig ( firebase as any ) ) ,
155
+ // switchMap(() => isPlatformBrowser(platformId) ? import('firebase/remote-config') : EMPTY),
156
+ // switchMap(() => import('@firebase/remote-config')),
157
+ // tap(rc => rc.registerRemoteConfig && rc.registerRemoteConfig(firebase as any)),
152
158
map ( ( ) => ɵfirebaseAppFactory ( options , zone , nameOrConfig ) ) ,
153
159
map ( app => ɵfetchInstance ( `${ app . name } .remote-config` , 'AngularFireRemoteConfig' , app , ( ) => {
154
- const rc = app . remoteConfig ( ) ;
160
+ const rc = getRemoteConfig ( app ) ;
155
161
if ( settings ) {
156
162
rc . settings = settings ;
157
163
}
@@ -166,35 +172,35 @@ export class AngularFireRemoteConfig {
166
172
) ;
167
173
168
174
const loadedRemoteConfig$ = remoteConfig$ . pipe (
169
- filter < firebase . remoteConfig . RemoteConfig > ( rc => ! ! rc )
175
+ filter < RemoteConfig > ( rc => ! ! rc )
170
176
) ;
171
177
172
- const default$ : Observable < { [ key : string ] : firebase . remoteConfig . Value } > = of ( Object . keys ( defaultConfig || { } ) . reduce (
178
+ const default$ : Observable < { [ key : string ] : ValueType } > = of ( Object . keys ( defaultConfig || { } ) . reduce (
173
179
( c , k ) => ( { ...c , [ k ] : new Value ( 'default' , defaultConfig [ k ] . toString ( ) ) } ) , { }
174
180
) ) ;
175
181
176
182
// we should filter out the defaults we provided to RC, since we have our own implementation
177
183
// that gives us a -1 for fetchTimeMillis (so filterFresh can filter them out)
178
- const filterOutDefaults = map < { [ key : string ] : firebase . remoteConfig . Value } , { [ key : string ] : firebase . remoteConfig . Value } > ( all =>
184
+ const filterOutDefaults = map < { [ key : string ] : ValueType } , { [ key : string ] : ValueType } > ( all =>
179
185
Object . keys ( all )
180
186
. filter ( key => all [ key ] . getSource ( ) !== 'default' )
181
187
. reduce ( ( acc , key ) => ( { ...acc , [ key ] : all [ key ] } ) , { } )
182
188
) ;
183
189
184
190
const existing$ = loadedRemoteConfig$ . pipe (
185
191
switchMap ( rc =>
186
- rc . activate ( )
187
- . then ( ( ) => rc . ensureInitialized ( ) )
188
- . then ( ( ) => rc . getAll ( ) )
192
+ activate ( rc )
193
+ . then ( ( ) => ensureInitialized ( rc ) )
194
+ . then ( ( ) => getAll ( rc ) )
189
195
) ,
190
196
filterOutDefaults
191
197
) ;
192
198
193
199
const fresh$ = loadedRemoteConfig$ . pipe (
194
200
switchMap ( rc => zone . runOutsideAngular ( ( ) =>
195
- rc . fetchAndActivate ( )
196
- . then ( ( ) => rc . ensureInitialized ( ) )
197
- . then ( ( ) => rc . getAll ( ) )
201
+ fetchAndActivate ( rc )
202
+ . then ( ( ) => ensureInitialized ( rc ) )
203
+ . then ( ( ) => getAll ( rc ) )
198
204
) ) ,
199
205
filterOutDefaults
200
206
) ;
0 commit comments