@@ -40,7 +40,14 @@ export class Value implements remoteConfig.Value {
40
40
asString ( ) { return this . _value }
41
41
asNumber ( ) { return Number ( this . _value ) || 0 }
42
42
getSource ( ) { return this . _source ; }
43
- constructor ( private _source : remoteConfig . ValueSource , private _value : string ) { }
43
+ constructor ( public _source : remoteConfig . ValueSource , public _value : string ) { }
44
+ }
45
+
46
+ // SEMVER use ConstructorParameters when we can support Typescript 3.6
47
+ export class KeyedValue extends Value {
48
+ constructor ( private key : string , source : remoteConfig . ValueSource , value : string ) {
49
+ super ( source , value ) ;
50
+ }
44
51
}
45
52
46
53
@Injectable ( {
@@ -50,8 +57,8 @@ export class AngularFireRemoteConfig {
50
57
51
58
private default$ : Observable < { [ key :string ] : remoteConfig . Value } > ;
52
59
53
- readonly changes : Observable < { } > ;
54
- readonly all : Observable < { [ key :string ] : remoteConfig . Value } > & { [ key :string ] : Observable < remoteConfig . Value > } ;
60
+ readonly changes : Observable < { key : string } & remoteConfig . Value > ;
61
+ readonly values : Observable < { [ key :string ] : remoteConfig . Value } > & { [ key :string ] : Observable < remoteConfig . Value > } ;
55
62
readonly numbers : Observable < { [ key :string ] : number } > & { [ key :string ] : Observable < number > } ;
56
63
readonly booleans : Observable < { [ key :string ] : boolean } > & { [ key :string ] : Observable < boolean > } ;
57
64
readonly strings : Observable < { [ key :string ] : string } > & { [ key :string ] : Observable < string > } ;
@@ -81,14 +88,15 @@ export class AngularFireRemoteConfig {
81
88
const defaultToStartWith = Object . keys ( defaultConfig || { } ) . reduce ( ( c , k ) => {
82
89
c [ k ] = new Value ( "default" , defaultConfig ! [ k ] . toString ( ) ) ;
83
90
return c ;
84
- } , { } ) ;
91
+ } , { } as { [ key : string ] : remoteConfig . Value } ) ;
85
92
86
93
const mapRemoteConfig = ( rc : { [ key :string ] : Value | remoteConfig . Value } ) => {
87
- return Object . keys ( rc ) . reduce ( ( c , key , index ) => {
94
+ const keys = Object . keys ( rc ) ;
95
+ return keys . reduce ( ( c , key , index ) => {
88
96
const value = rc [ key ] ;
89
- c [ index ] = { key, value } ;
97
+ c [ index ] = new KeyedValue ( key , value . getSource ( ) , value . asString ( ) ) ;
90
98
return c ;
91
- } , new Array < { } > ( rc . length ) ) ;
99
+ } , new Array < KeyedValue > ( keys . length ) ) ;
92
100
}
93
101
94
102
const proxy : AngularFireRemoteConfig = _lazySDKProxy ( this , remoteConfig , zone ) ;
@@ -105,40 +113,40 @@ export class AngularFireRemoteConfig {
105
113
switchMap ( ( ) => proxy . getAll ( ) )
106
114
) ;
107
115
108
- this . all = new Proxy ( concat ( this . default$ , existing , fresh ) , {
116
+ this . values = new Proxy ( concat ( this . default$ , existing , fresh ) , {
109
117
get : ( self , name :string ) => self [ name ] || self . pipe (
110
118
map ( rc => rc [ name ] ? rc [ name ] : undefined ) ,
111
119
distinctUntilChanged ( ( a , b ) => JSON . stringify ( a ) === JSON . stringify ( b ) )
112
120
)
113
- } ) as any ;
121
+ } ) as any ; // TODO figure out the types here
114
122
115
- this . changes = this . all . pipe (
123
+ this . changes = this . values . pipe (
116
124
switchMap ( all => of ( ...mapRemoteConfig ( all ) ) )
117
- ) ;
125
+ ) as any ; // TODO figure out the types here
118
126
119
- const allAs = ( type : 'String' | 'Boolean' | 'Number' ) => this . all . pipe (
127
+ const allAs = ( type : 'String' | 'Boolean' | 'Number' ) => this . values . pipe (
120
128
map ( all => Object . keys ( all ) . reduce ( ( c , k ) => {
121
129
c [ k ] = all [ k ] [ `as${ type } ` ] ( ) ;
122
130
return c ;
123
131
} , { } ) )
124
- ) as any ;
132
+ ) as any ; // TODO figure out the types here
125
133
126
134
this . strings = new Proxy ( allAs ( 'String' ) , {
127
- get : ( self , name :string ) => self [ name ] || this . all . pipe (
135
+ get : ( self , name :string ) => self [ name ] || this . values . pipe (
128
136
map ( rc => rc [ name ] ? rc [ name ] . asString ( ) : undefined ) ,
129
137
distinctUntilChanged ( )
130
138
)
131
139
} ) ;
132
140
133
141
this . booleans = new Proxy ( allAs ( 'Boolean' ) , {
134
- get : ( self , name :string ) => self [ name ] || this . all . pipe (
142
+ get : ( self , name :string ) => self [ name ] || this . values . pipe (
135
143
map ( rc => rc [ name ] ? rc [ name ] . asBoolean ( ) : false ) ,
136
144
distinctUntilChanged ( )
137
145
)
138
146
} ) ;
139
147
140
148
this . numbers = new Proxy ( allAs ( 'Number' ) , {
141
- get : ( self , name :string ) => self [ name ] || this . all . pipe (
149
+ get : ( self , name :string ) => self [ name ] || this . values . pipe (
142
150
map ( rc => rc [ name ] ? rc [ name ] . asNumber ( ) : 0 ) ,
143
151
distinctUntilChanged ( )
144
152
)
0 commit comments