Skip to content

Commit eed06e8

Browse files
committed
Address comments
1 parent 388a7c0 commit eed06e8

File tree

6 files changed

+52
-50
lines changed

6 files changed

+52
-50
lines changed

packages/database/src/core/PersistentConnection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,8 @@ export class PersistentConnection extends ServerActions {
948948

949949
// Puts depend on having received the corresponding data update from the server before they complete, so we must
950950
// make sure to send listens before puts.
951-
forEach(this.listens_, (_, queries) => {
952-
forEach(queries, (_, listenSpec) => {
951+
forEach(this.listens_, (_pathString, queries) => {
952+
forEach(queries, (_key, listenSpec) => {
953953
this.sendListen_(listenSpec);
954954
});
955955
});

packages/database/src/core/snap/IndexMap.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ export class IndexMap {
7070
const sortedMap = safeGet(this.indexes_, indexKey);
7171
if (!sortedMap) throw new Error('No index defined for ' + indexKey);
7272

73-
if (sortedMap === fallbackObject) {
73+
if (sortedMap instanceof SortedMap) {
74+
return sortedMap;
75+
} else {
7476
// The index exists, but it falls back to just name comparison. Return null so that the calling code uses the
7577
// regular child map
7678
return null;
77-
} else {
78-
return sortedMap as SortedMap<NamedNode, Node>;
7979
}
8080
}
8181

packages/database/src/core/snap/Node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ export interface Node {
116116
forEachChild(index: Index, action: (a: string, b: Node) => void): any;
117117

118118
/**
119-
* @param {boolean=} exportFormat True for export format (also wire protocol format).
120-
* @return {*} Value of this node as JSON.
119+
* @param exportFormat True for export format (also wire protocol format).
120+
* @return Value of this node as JSON.
121121
*/
122122
val(exportFormat?: boolean): any;
123123

packages/database/src/core/view/ChildChangeAccumulator.ts

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,15 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { getValues, safeGet } from '@firebase/util';
1918
import { Change } from './Change';
2019
import { assert, assertionError } from '@firebase/util';
2120

22-
/**
23-
* @constructor
24-
*/
2521
export class ChildChangeAccumulator {
26-
private changeMap_: { [k: string]: Change } = {};
22+
private readonly changeMap: Map<string, Change> = new Map();
2723

28-
/**
29-
* @param {!Change} change
30-
*/
3124
trackChildChange(change: Change) {
3225
const type = change.type;
33-
const childKey /** @type {!string} */ = change.childName;
26+
const childKey = change.childName!;
3427
assert(
3528
type == Change.CHILD_ADDED ||
3629
type == Change.CHILD_CHANGED ||
@@ -41,44 +34,50 @@ export class ChildChangeAccumulator {
4134
childKey !== '.priority',
4235
'Only non-priority child changes can be tracked.'
4336
);
44-
const oldChange = safeGet(this.changeMap_, childKey) as Change;
37+
const oldChange = this.changeMap.get(childKey);
4538
if (oldChange) {
4639
const oldType = oldChange.type;
4740
if (type == Change.CHILD_ADDED && oldType == Change.CHILD_REMOVED) {
48-
this.changeMap_[childKey] = Change.childChangedChange(
41+
this.changeMap.set(
4942
childKey,
50-
change.snapshotNode,
51-
oldChange.snapshotNode
43+
Change.childChangedChange(
44+
childKey,
45+
change.snapshotNode,
46+
oldChange.snapshotNode
47+
)
5248
);
5349
} else if (
5450
type == Change.CHILD_REMOVED &&
5551
oldType == Change.CHILD_ADDED
5652
) {
57-
delete this.changeMap_[childKey];
53+
this.changeMap.delete(childKey);
5854
} else if (
5955
type == Change.CHILD_REMOVED &&
6056
oldType == Change.CHILD_CHANGED
6157
) {
62-
this.changeMap_[childKey] = Change.childRemovedChange(
58+
this.changeMap.set(
6359
childKey,
64-
oldChange.oldSnap
60+
Change.childRemovedChange(childKey, oldChange.oldSnap)
6561
);
6662
} else if (
6763
type == Change.CHILD_CHANGED &&
6864
oldType == Change.CHILD_ADDED
6965
) {
70-
this.changeMap_[childKey] = Change.childAddedChange(
66+
this.changeMap.set(
7167
childKey,
72-
change.snapshotNode
68+
Change.childAddedChange(childKey, change.snapshotNode)
7369
);
7470
} else if (
7571
type == Change.CHILD_CHANGED &&
7672
oldType == Change.CHILD_CHANGED
7773
) {
78-
this.changeMap_[childKey] = Change.childChangedChange(
74+
this.changeMap.set(
7975
childKey,
80-
change.snapshotNode,
81-
oldChange.oldSnap
76+
Change.childChangedChange(
77+
childKey,
78+
change.snapshotNode,
79+
oldChange.oldSnap
80+
)
8281
);
8382
} else {
8483
throw assertionError(
@@ -89,14 +88,11 @@ export class ChildChangeAccumulator {
8988
);
9089
}
9190
} else {
92-
this.changeMap_[childKey] = change;
91+
this.changeMap.set(childKey, change);
9392
}
9493
}
9594

96-
/**
97-
* @return {!Array.<!Change>}
98-
*/
9995
getChanges(): Change[] {
100-
return getValues(this.changeMap_);
96+
return Array.from(this.changeMap.values());
10197
}
10298
}

packages/polyfill/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@ import 'whatwg-fetch';
2121
// Promise
2222
import 'promise-polyfill/lib/polyfill';
2323

24-
// ES6
24+
// ES Stable
2525
import 'core-js/features/array/find';
2626
import 'core-js/features/array/find-index';
27+
import 'core-js/features/array/from';
2728
import 'core-js/features/object/assign';
29+
import 'core-js/features/object/entries';
30+
import 'core-js/features/object/values';
2831
import 'core-js/features/string/starts-with';
2932
import 'core-js/features/string/repeat';
3033
import 'core-js/features/symbol';
3134
import 'core-js/features/symbol/iterator';
35+
import 'core-js/features/map';
36+
import 'core-js/features/set';

packages/util/src/obj.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function forEach<T extends object>(
4343
obj: T,
4444
fn: (key: Keys<T>, value: Values<T>) => void
4545
) {
46-
for (var key of Object.keys(obj)) {
46+
for (const key of Object.keys(obj)) {
4747
// Object.keys() doesn't return an Array<keyof T>
4848
// https://github.com/microsoft/TypeScript/pull/12253#issuecomment-263132208
4949
fn(key as Keys<T>, obj[key]);
@@ -77,7 +77,12 @@ export function isNonNullObject(obj: unknown): obj is object {
7777
}
7878

7979
export function isEmpty(obj: object): obj is {} {
80-
return Object.keys(obj).length === 0;
80+
for (const key in obj) {
81+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
82+
return false;
83+
}
84+
}
85+
return true;
8186
}
8287

8388
export function getCount(obj: object): number {
@@ -89,8 +94,8 @@ export function map<T extends object, V, U extends { [key in keyof T]: V }>(
8994
fn: (value: Values<T>, key: Keys<T>, obj: T) => V,
9095
opt_obj?: unknown
9196
): U {
92-
var res: Partial<U> = {};
93-
for (var [key, value] of Object.entries(obj)) {
97+
const res: Partial<U> = {};
98+
for (const [key, value] of Object.entries(obj)) {
9499
res[key] = fn.call(opt_obj, value, key, obj);
95100
}
96101
return res as U;
@@ -101,7 +106,7 @@ export function findKey<T extends object>(
101106
fn: <K extends Keys<T>>(value: T[K], key: K, obj: T) => boolean,
102107
opt_this?: unknown
103108
): keyof T | undefined {
104-
for (var [key, value] of Object.entries(obj)) {
109+
for (const [key, value] of Object.entries(obj)) {
105110
if (fn.call(opt_this, value, key, obj)) {
106111
return key as keyof T;
107112
}
@@ -114,21 +119,17 @@ export function findValue<T extends object>(
114119
fn: (value: Values<T>, key: Keys<T>, obj: T) => boolean,
115120
opt_this?: unknown
116121
): Values<T> | undefined {
117-
var key = findKey(obj, fn, opt_this);
122+
const key = findKey(obj, fn, opt_this);
118123
return key && obj[key];
119124
}
120125

121126
export function getAnyKey<T extends object>(obj: T): keyof T | undefined {
122-
const keys = Object.keys(obj);
123-
if (keys.length > 0) {
124-
return keys[0] as keyof T;
125-
} else {
126-
return undefined;
127+
for (const key in obj) {
128+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
129+
return key;
130+
}
127131
}
128-
}
129-
130-
export function getValues<T extends object>(obj: T): Array<Values<T>> {
131-
return Object.values(obj);
132+
return undefined;
132133
}
133134

134135
/**
@@ -142,7 +143,7 @@ export function every<T extends object>(
142143
obj: T,
143144
fn: (key: Keys<T>, value: Values<T>) => boolean
144145
): boolean {
145-
for (var [key, value] of Object.entries(obj)) {
146+
for (const [key, value] of Object.entries(obj)) {
146147
if (!fn(key as Keys<T>, value)) {
147148
return false;
148149
}

0 commit comments

Comments
 (0)