Skip to content

Commit 1e39052

Browse files
committed
Minor changes to RC
1 parent b8b351a commit 1e39052

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

src/remote-config/remote-config.ts

+24-16
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ export class Value implements remoteConfig.Value {
4040
asString() { return this._value }
4141
asNumber() { return Number(this._value) || 0 }
4242
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+
}
4451
}
4552

4653
@Injectable({
@@ -50,8 +57,8 @@ export class AngularFireRemoteConfig {
5057

5158
private default$: Observable<{[key:string]: remoteConfig.Value}>;
5259

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>};
5562
readonly numbers: Observable<{[key:string]: number}> & {[key:string]: Observable<number>};
5663
readonly booleans: Observable<{[key:string]: boolean}> & {[key:string]: Observable<boolean>};
5764
readonly strings: Observable<{[key:string]: string}> & {[key:string]: Observable<string>};
@@ -81,14 +88,15 @@ export class AngularFireRemoteConfig {
8188
const defaultToStartWith = Object.keys(defaultConfig || {}).reduce((c, k) => {
8289
c[k] = new Value("default", defaultConfig![k].toString());
8390
return c;
84-
}, {});
91+
}, {} as {[key:string]: remoteConfig.Value});
8592

8693
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) => {
8896
const value = rc[key];
89-
c[index] = { key, value };
97+
c[index] = new KeyedValue(key, value.getSource(), value.asString());
9098
return c;
91-
}, new Array<{}>(rc.length));
99+
}, new Array<KeyedValue>(keys.length));
92100
}
93101

94102
const proxy: AngularFireRemoteConfig = _lazySDKProxy(this, remoteConfig, zone);
@@ -105,40 +113,40 @@ export class AngularFireRemoteConfig {
105113
switchMap(() => proxy.getAll())
106114
);
107115

108-
this.all = new Proxy(concat(this.default$, existing, fresh), {
116+
this.values = new Proxy(concat(this.default$, existing, fresh), {
109117
get: (self, name:string) => self[name] || self.pipe(
110118
map(rc => rc[name] ? rc[name] : undefined),
111119
distinctUntilChanged((a,b) => JSON.stringify(a) === JSON.stringify(b))
112120
)
113-
}) as any;
121+
}) as any; // TODO figure out the types here
114122

115-
this.changes = this.all.pipe(
123+
this.changes = this.values.pipe(
116124
switchMap(all => of(...mapRemoteConfig(all)))
117-
);
125+
) as any; // TODO figure out the types here
118126

119-
const allAs = (type: 'String'|'Boolean'|'Number') => this.all.pipe(
127+
const allAs = (type: 'String'|'Boolean'|'Number') => this.values.pipe(
120128
map(all => Object.keys(all).reduce((c, k) => {
121129
c[k] = all[k][`as${type}`]();
122130
return c;
123131
}, {}))
124-
) as any;
132+
) as any; // TODO figure out the types here
125133

126134
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(
128136
map(rc => rc[name] ? rc[name].asString() : undefined),
129137
distinctUntilChanged()
130138
)
131139
});
132140

133141
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(
135143
map(rc => rc[name] ? rc[name].asBoolean() : false),
136144
distinctUntilChanged()
137145
)
138146
});
139147

140148
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(
142150
map(rc => rc[name] ? rc[name].asNumber() : 0),
143151
distinctUntilChanged()
144152
)

0 commit comments

Comments
 (0)