@@ -21,13 +21,12 @@ import { debug, error } from '../util/log';
21
21
import { primitiveComparator } from '../util/misc' ;
22
22
import { SortedSet } from '../util/sorted_set' ;
23
23
import { isSafeInteger } from '../util/types' ;
24
- import { forEach } from '../util/obj' ;
25
24
import * as objUtils from '../util/obj' ;
26
25
27
26
const LOG_TAG = 'SharedClientState' ;
28
27
29
- // The format of a the key for the client state in LocalStorage is:
30
- // fs_clients_<persistence_prefix>_<instance_key>
28
+ // The format of the LocalStorage key storing the client state is:
29
+ // fs_clients_<persistence_prefix>_<instance_key>
31
30
const CLIENT_STATE_KEY_PREFIX = 'fs_clients' ;
32
31
33
32
/**
@@ -39,7 +38,7 @@ export type ClientKey = string;
39
38
* The `SharedClientState` keeps track of the global state of the mutations
40
39
* and query targets for all active clients with the same persistence key (i.e.
41
40
* project ID and FirebaseApp name). It relays local changes to other clients
42
- * and updates its local state as new metadata is observed.
41
+ * and updates its local state as new state is observed.
43
42
*
44
43
* `SharedClientState` is primarily used for synchronization in Multi-Tab
45
44
* environments. Each tab is responsible for registering its active query
@@ -103,8 +102,8 @@ interface ClientStateSchema {
103
102
104
103
/**
105
104
* Metadata state of a single client. Includes query targets, the minimum
106
- * pending and maximum pending mutation batch ID the last update time of this
107
- * state.
105
+ * pending and maximum pending mutation batch ID, as well as the last update
106
+ * time of this state.
108
107
*/
109
108
// Visible for testing.
110
109
export interface ClientState {
@@ -115,9 +114,9 @@ export interface ClientState {
115
114
}
116
115
117
116
/**
118
- * This class represents the immutable ClientState of clients read from
119
- * LocalStorage. It contains the list of all active query targets and the range
120
- * of the client's pending mutation batch IDs.
117
+ * This class represents the immutable ClientState for a client read from
118
+ * LocalStorage. It contains the list of its active query targets and the range
119
+ * of its pending mutation batch IDs.
121
120
*/
122
121
class RemoteClientState implements ClientState {
123
122
constructor (
@@ -129,7 +128,7 @@ class RemoteClientState implements ClientState {
129
128
) { }
130
129
131
130
/**
132
- * Parses a ClientState from its JSON representation in LocalStorage.
131
+ * Parses a ClientState from the JSON representation in LocalStorage.
133
132
* Logs a warning and returns null if the data could not be parsed.
134
133
*/
135
134
static fromLocalStorageEntry (
@@ -258,7 +257,7 @@ export class LocalClientState implements ClientState {
258
257
/**
259
258
* `WebStorageSharedClientState` uses WebStorage (window.localStorage) as the
260
259
* backing store for the SharedClientState. It keeps track of all active
261
- * clients and supports modification of the current client's data.
260
+ * clients and supports modifications of the current client's data.
262
261
*/
263
262
export class WebStorageSharedClientState implements SharedClientState {
264
263
private readonly storage : Storage ;
@@ -322,11 +321,9 @@ export class WebStorageSharedClientState implements SharedClientState {
322
321
323
322
getAllActiveQueryTargets ( ) : SortedSet < TargetId > {
324
323
let activeTargets = new SortedSet < TargetId > ( primitiveComparator ) ;
325
-
326
324
objUtils . forEach ( this . activeClients , ( key , value ) => {
327
325
activeTargets = activeTargets . unionWith ( value . activeTargetIds ) ;
328
326
} ) ;
329
-
330
327
return activeTargets ;
331
328
}
332
329
@@ -371,7 +368,6 @@ export class WebStorageSharedClientState implements SharedClientState {
371
368
event . key !== this . storageKey ,
372
369
'Received LocalStorage notification for local change.'
373
370
) ;
374
- console . log ( event . newValue ) ;
375
371
const clientKey = this . fromLocalStorageClientKey ( event . key ) ;
376
372
if ( clientKey ) {
377
373
if ( event . newValue == null ) {
@@ -395,7 +391,7 @@ export class WebStorageSharedClientState implements SharedClientState {
395
391
396
392
private persistState ( ) : void {
397
393
// TODO(multitab): Consider rate limiting/combining state updates for
398
- // clients that frequently change update client state.
394
+ // clients that frequently update their client state.
399
395
assert ( this . started , 'WebStorageSharedClientState used before started.' ) ;
400
396
debug ( LOG_TAG , 'Persisting state in LocalStorage' ) ;
401
397
this . localClientState . refreshLastUpdateTime ( ) ;
@@ -405,7 +401,7 @@ export class WebStorageSharedClientState implements SharedClientState {
405
401
) ;
406
402
}
407
403
408
- /** Assembles the key for client states in LocalStorage */
404
+ /** Assembles the key for a client state in LocalStorage */
409
405
private toLocalStorageClientKey ( clientKey : string ) : string {
410
406
assert (
411
407
clientKey . indexOf ( '_' ) === - 1 ,
0 commit comments