@bitsocial/bitsocial-react-hooks 0.1.65 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,12 @@
1
1
  import { Communities, CommunitySyncState } from "../../types.js";
2
2
  export declare const COMMUNITY_UPDATE_INTERVAL_MS: number;
3
+ export declare const COMMUNITY_UPDATE_STOP_GRACE_MS: number;
3
4
  interface CommunitySyncStatus {
4
5
  syncState: CommunitySyncState;
5
6
  lastFetchAttemptAt?: number;
6
7
  lastSuccessfulFetchAt?: number;
7
8
  lastRetriableError?: Error;
9
+ stoppedUntilUsed?: true;
8
10
  }
9
11
  export declare const isRetriableCommunityLoadError: (error: Error) => boolean;
10
12
  export type CommunitiesState = {
@@ -16,6 +18,8 @@ export type CommunitiesState = {
16
18
  [communityAddress: string]: CommunitySyncStatus;
17
19
  };
18
20
  addCommunityToStore: Function;
21
+ startCommunityAutoUpdate: Function;
22
+ stopCommunityAutoUpdate: Function;
19
23
  refreshCommunity: Function;
20
24
  editCommunity: Function;
21
25
  createCommunity: Function;
@@ -1 +1 @@
1
- {"version":3,"file":"communities-store.d.ts","sourceRoot":"","sources":["../../../src/stores/communities/communities-store.ts"],"names":[],"mappings":"AAQA,OAAO,EAEL,WAAW,EAGX,kBAAkB,EAEnB,MAAM,aAAa,CAAC;AAcrB,eAAO,MAAM,4BAA4B,QAAiB,CAAC;AAmB3D,UAAU,mBAAmB;IAC3B,SAAS,EAAE,kBAAkB,CAAC;IAC9B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAG/B,kBAAkB,CAAC,EAAE,KAAK,CAAC;CAC5B;AA2JD,eAAO,MAAM,6BAA6B,GAAI,OAAO,KAAK,YAQzD,CAAC;AAqDF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,EAAE;QAAE,CAAC,gBAAgB,EAAE,MAAM,GAAG,KAAK,EAAE,CAAA;KAAE,CAAC;IAChD,YAAY,EAAE;QAAE,CAAC,gBAAgB,EAAE,MAAM,GAAG,mBAAmB,CAAA;KAAE,CAAC;IAClE,mBAAmB,EAAE,QAAQ,CAAC;IAC9B,gBAAgB,EAAE,QAAQ,CAAC;IAC3B,aAAa,EAAE,QAAQ,CAAC;IACxB,eAAe,EAAE,QAAQ,CAAC;IAC1B,eAAe,EAAE,QAAQ,CAAC;CAC3B,CAAC;AAEF,QAAA,MAAM,gBAAgB,+EA+ZrB,CAAC;AAKF,eAAO,MAAM,qBAAqB,qBAWjC,CAAC;AAGF,eAAO,MAAM,gCAAgC,qBAG5C,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"communities-store.d.ts","sourceRoot":"","sources":["../../../src/stores/communities/communities-store.ts"],"names":[],"mappings":"AAQA,OAAO,EAEL,WAAW,EAGX,kBAAkB,EAEnB,MAAM,aAAa,CAAC;AAcrB,eAAO,MAAM,4BAA4B,QAAiB,CAAC;AAQ3D,eAAO,MAAM,8BAA8B,QAAgB,CAAC;AAqC5D,UAAU,mBAAmB;IAC3B,SAAS,EAAE,kBAAkB,CAAC;IAC9B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAG/B,kBAAkB,CAAC,EAAE,KAAK,CAAC;IAE3B,gBAAgB,CAAC,EAAE,IAAI,CAAC;CACzB;AAoQD,eAAO,MAAM,6BAA6B,GAAI,OAAO,KAAK,YAQzD,CAAC;AAqDF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,EAAE;QAAE,CAAC,gBAAgB,EAAE,MAAM,GAAG,KAAK,EAAE,CAAA;KAAE,CAAC;IAChD,YAAY,EAAE;QAAE,CAAC,gBAAgB,EAAE,MAAM,GAAG,mBAAmB,CAAA;KAAE,CAAC;IAClE,mBAAmB,EAAE,QAAQ,CAAC;IAC9B,wBAAwB,EAAE,QAAQ,CAAC;IACnC,uBAAuB,EAAE,QAAQ,CAAC;IAClC,gBAAgB,EAAE,QAAQ,CAAC;IAC3B,aAAa,EAAE,QAAQ,CAAC;IACxB,eAAe,EAAE,QAAQ,CAAC;IAC1B,eAAe,EAAE,QAAQ,CAAC;CAC3B,CAAC;AAEF,QAAA,MAAM,gBAAgB,+EA8frB,CAAC;AAKF,eAAO,MAAM,qBAAqB,qBAejC,CAAC;AAGF,eAAO,MAAM,gCAAgC,qBAG5C,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -7,6 +7,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
10
21
  import assert from "../../lib/assert.js";
11
22
  import localForageLru from "../../lib/localforage-lru/index.js";
12
23
  const communitiesDatabase = localForageLru.createInstance({
@@ -22,9 +33,18 @@ import communitiesPagesStore from "../communities-pages/index.js";
22
33
  import { getCommunityLookupOptions, getCommunityRefKey } from "../../lib/community-ref.js";
23
34
  import { createPkcCommunity, getPkcCommunity, getPkcCommunityAddresses, getPkcCreateCommunity, getPkcGetCommunity, } from "../../lib/pkc-compat.js";
24
35
  export const COMMUNITY_UPDATE_INTERVAL_MS = 15 * 60 * 1000;
36
+ // How long a community keeps updating after nothing uses it anymore. pkc-js forgets the record
37
+ // CIDs and gateway ETags it already loaded when a community stops, so every restart downloads the
38
+ // whole record again, while a running loop downloads it once per publish. Communities publish
39
+ // between every ~20 seconds when busy and every 15 minutes when idle, so 2 minutes keeps quick
40
+ // back-and-forth navigation from re-downloading records and bounds what an abandoned busy
41
+ // community costs to about one restart's worth of downloads.
42
+ export const COMMUNITY_UPDATE_STOP_GRACE_MS = 2 * 60 * 1000;
25
43
  let pkcGetCommunityPending = {};
26
- // Key pollers by community so delete/reset can stop the matching live instance.
27
- const communityUpdatePollers = {};
44
+ const liveCommunities = {};
45
+ // hooks and feeds that need a community kept updating, the loop stops after the last one leaves
46
+ const communityUpdateSubscribers = {};
47
+ const communityStopTimers = {};
28
48
  // reset all event listeners in between tests
29
49
  const listeners = [];
30
50
  const COMMUNITY_ERROR_UPDATE_GRACE_MS = 1000;
@@ -73,35 +93,141 @@ const createCommunityWithLookupFallback = (pkc, communityLookupOptions, communit
73
93
  }
74
94
  throw Error(`communitiesStore.addCommunityToStore failed getting community '${communityKey}'`);
75
95
  });
76
- const updateCommunity = (community, { communityAddressOrRef, communityKey, }) => {
77
- community.update().catch((error) => log.trace("community.update error", {
96
+ const getCommunityKey = (communityAddressOrRef) => typeof communityAddressOrRef === "string"
97
+ ? communityAddressOrRef
98
+ : getCommunityRefKey(communityAddressOrRef);
99
+ const hasCommunityUpdateSubscribers = (communityKey) => { var _a; return (((_a = communityUpdateSubscribers[communityKey]) === null || _a === void 0 ? void 0 : _a.size) || 0) > 0; };
100
+ const updateCommunity = (communityKey, liveCommunity) => {
101
+ const { community, communityAddressOrRef } = liveCommunity;
102
+ liveCommunity.updateCall = Promise.resolve()
103
+ .then(() => community.update())
104
+ .catch((error) => log.trace("community.update error", {
78
105
  communityAddressOrRef,
79
106
  communityKey,
80
107
  community,
81
108
  error,
82
109
  }));
83
110
  };
84
- const startCommunityUpdatePolling = (community, { communityAddressOrRef, communityKey, }) => {
85
- stopCommunityUpdatePolling(communityKey);
86
- updateCommunity(community, { communityAddressOrRef, communityKey });
87
- communityUpdatePollers[communityKey] = {
88
- community,
89
- updateInterval: setInterval(() => updateCommunity(community, { communityAddressOrRef, communityKey }), COMMUNITY_UPDATE_INTERVAL_MS),
90
- };
111
+ const startCommunityUpdatePolling = (communityKey, liveCommunity) => {
112
+ clearInterval(liveCommunity.updateInterval);
113
+ liveCommunity.openingUpdatePending = true;
114
+ liveCommunity.stopWhenOpeningUpdateEnds = false;
115
+ updateCommunity(communityKey, liveCommunity);
116
+ liveCommunity.updateInterval = setInterval(() => updateCommunity(communityKey, liveCommunity), COMMUNITY_UPDATE_INTERVAL_MS);
117
+ };
118
+ const pauseCommunityUpdatePolling = (communityKey) => {
119
+ const liveCommunity = liveCommunities[communityKey];
120
+ if (!(liveCommunity === null || liveCommunity === void 0 ? void 0 : liveCommunity.updateInterval)) {
121
+ return;
122
+ }
123
+ clearInterval(liveCommunity.updateInterval);
124
+ liveCommunity.updateInterval = undefined;
125
+ liveCommunity.openingUpdatePending = false;
126
+ liveCommunity.stopWhenOpeningUpdateEnds = false;
127
+ liveCommunity.replayRecordId = undefined;
128
+ clearPendingCommunityErrors(communityKey);
129
+ const { community, updateCall } = liveCommunity;
130
+ // stopping while update() is still attaching to the shared updating instance would leave its
131
+ // listeners attached, so wait for the call to return first
132
+ const stopping = (() => __awaiter(void 0, void 0, void 0, function* () {
133
+ yield updateCall;
134
+ if (typeof community.stop !== "function") {
135
+ return;
136
+ }
137
+ try {
138
+ yield community.stop();
139
+ }
140
+ catch (error) {
141
+ log.trace("community.stop error", { communityKey, community, error });
142
+ }
143
+ }))();
144
+ liveCommunity.stopping = stopping;
145
+ stopping.finally(() => {
146
+ if (liveCommunity.stopping === stopping) {
147
+ liveCommunity.stopping = undefined;
148
+ }
149
+ });
150
+ log("communitiesStore community update loop stopped", { communityKey });
151
+ };
152
+ const resumeCommunityUpdatePolling = (communityKey) => __awaiter(void 0, void 0, void 0, function* () {
153
+ var _a;
154
+ const liveCommunity = liveCommunities[communityKey];
155
+ if (!liveCommunity || liveCommunity.updateInterval) {
156
+ return;
157
+ }
158
+ // update() is a no-op until a stop in progress ends
159
+ if (liveCommunity.stopping) {
160
+ yield liveCommunity.stopping;
161
+ }
162
+ if (liveCommunities[communityKey] !== liveCommunity ||
163
+ liveCommunity.updateInterval ||
164
+ !hasCommunityUpdateSubscribers(communityKey)) {
165
+ return;
166
+ }
167
+ liveCommunity.replayRecordId = getCommunityRecordId(liveCommunity.community);
168
+ liveCommunity.replayRefreshesFetchedAt = false;
169
+ startCommunityUpdatePolling(communityKey, liveCommunity);
170
+ log("communitiesStore community update loop restarted", { communityKey });
171
+ // joining a shared pkc-js instance that another consumer kept updating emits no state change
172
+ // until its next fetch, so take its current state
173
+ yield liveCommunity.updateCall;
174
+ const { updatingState } = liveCommunity.community;
175
+ if (liveCommunity.updateInterval &&
176
+ typeof updatingState === "string" &&
177
+ updatingState !== "stopped" &&
178
+ ((_a = communitiesStore.getState().syncStatuses[communityKey]) === null || _a === void 0 ? void 0 : _a.stoppedUntilUsed)) {
179
+ liveCommunity.onUpdatingStateChange(updatingState);
180
+ }
181
+ });
182
+ const clearCommunityStopTimer = (communityKey) => {
183
+ clearTimeout(communityStopTimers[communityKey]);
184
+ delete communityStopTimers[communityKey];
185
+ };
186
+ const scheduleCommunityUpdateStop = (communityKey) => {
187
+ clearCommunityStopTimer(communityKey);
188
+ communityStopTimers[communityKey] = setTimeout(() => {
189
+ delete communityStopTimers[communityKey];
190
+ const liveCommunity = liveCommunities[communityKey];
191
+ if (hasCommunityUpdateSubscribers(communityKey) || !(liveCommunity === null || liveCommunity === void 0 ? void 0 : liveCommunity.updateInterval)) {
192
+ return;
193
+ }
194
+ // stopping before the first fetch ends would leave a store-level caller without the record
195
+ // it loaded the community for
196
+ if (liveCommunity.openingUpdatePending) {
197
+ liveCommunity.stopWhenOpeningUpdateEnds = true;
198
+ return;
199
+ }
200
+ pauseCommunityUpdatePolling(communityKey);
201
+ }, COMMUNITY_UPDATE_STOP_GRACE_MS);
202
+ };
203
+ const endOpeningCommunityUpdate = (communityKey, liveCommunity) => {
204
+ if (!liveCommunity.openingUpdatePending) {
205
+ return;
206
+ }
207
+ liveCommunity.openingUpdatePending = false;
208
+ if (!liveCommunity.stopWhenOpeningUpdateEnds) {
209
+ return;
210
+ }
211
+ liveCommunity.stopWhenOpeningUpdateEnds = false;
212
+ if (!hasCommunityUpdateSubscribers(communityKey)) {
213
+ pauseCommunityUpdatePolling(communityKey);
214
+ }
91
215
  };
92
216
  const stopCommunityUpdatePolling = (communityKey) => {
93
- const polling = communityUpdatePollers[communityKey];
94
- if (!polling) {
217
+ clearCommunityStopTimer(communityKey);
218
+ const liveCommunity = liveCommunities[communityKey];
219
+ if (!liveCommunity) {
95
220
  return;
96
221
  }
97
222
  clearPendingCommunityErrors(communityKey);
98
- clearInterval(polling.updateInterval);
99
- polling.community.removeAllListeners();
100
- const listenerIndex = listeners.indexOf(polling.community);
223
+ clearInterval(liveCommunity.updateInterval);
224
+ liveCommunity.updateInterval = undefined;
225
+ liveCommunity.community.removeAllListeners();
226
+ const listenerIndex = listeners.indexOf(liveCommunity.community);
101
227
  if (listenerIndex >= 0) {
102
228
  listeners.splice(listenerIndex, 1);
103
229
  }
104
- delete communityUpdatePollers[communityKey];
230
+ delete liveCommunities[communityKey];
105
231
  };
106
232
  const clearPendingCommunityErrors = (communityKey) => {
107
233
  var _a;
@@ -275,6 +401,11 @@ const communitiesStore = createStore((setState, getState) => ({
275
401
  if (!isFromCache) {
276
402
  yield communitiesDatabase.setItem(communityKey, firstCommunityState);
277
403
  }
404
+ // another load of this community, e.g. by another account, finished first and keeps it
405
+ // updating, so this instance is discarded before it starts updating
406
+ if (liveCommunities[communityKey]) {
407
+ return;
408
+ }
278
409
  log("communitiesStore.addCommunityToStore", {
279
410
  communityAddressOrRef,
280
411
  communityKey,
@@ -284,16 +415,46 @@ const communitiesStore = createStore((setState, getState) => ({
284
415
  setState((state) => ({
285
416
  communities: Object.assign(Object.assign({}, state.communities), { [communityKey]: firstCommunityState }),
286
417
  }));
287
- // pkc-js re-emits the record a community was created with when update() starts
288
- let cachedRecordId = isFromCache ? getCommunityRecordId(firstCommunityState) : undefined;
418
+ const liveCommunity = {
419
+ community,
420
+ communityAddressOrRef,
421
+ // pkc-js re-emits the record a community was created with when update() starts
422
+ replayRecordId: isFromCache ? getCommunityRecordId(firstCommunityState) : undefined,
423
+ replayRefreshesFetchedAt: true,
424
+ openingUpdatePending: false,
425
+ stopWhenOpeningUpdateEnds: false,
426
+ onUpdatingStateChange: (updatingState) => {
427
+ setState((state) => {
428
+ const syncStatuses = getNextSyncStatuses(state, communityKey, normalizeCommunitySyncState(updatingState));
429
+ const _a = syncStatuses[communityKey], { stoppedUntilUsed: _stoppedUntilUsed } = _a, syncStatus = __rest(_a, ["stoppedUntilUsed"]);
430
+ // the loop is not running when the store stopped the community itself
431
+ syncStatuses[communityKey] =
432
+ updatingState === "stopped" && !liveCommunity.updateInterval
433
+ ? Object.assign(Object.assign({}, syncStatus), { stoppedUntilUsed: true }) : syncStatus;
434
+ return {
435
+ syncStatuses,
436
+ communities: Object.assign(Object.assign({}, state.communities), { [communityKey]: Object.assign(Object.assign({}, state.communities[communityKey]), { updatingState }) }),
437
+ };
438
+ });
439
+ if (updatingState === "succeeded" ||
440
+ updatingState === "failed" ||
441
+ updatingState === "waiting-retry") {
442
+ endOpeningCommunityUpdate(communityKey, liveCommunity);
443
+ }
444
+ },
445
+ };
289
446
  // the community has published new posts
290
447
  community.on("update", (updatedCommunity) => __awaiter(this, void 0, void 0, function* () {
291
448
  clearPendingCommunityErrors(communityKey);
292
449
  setState((state) => clearStoredCommunityErrorsState(state, communityKey));
293
- const isCachedRecordReplay = cachedRecordId !== undefined &&
294
- getCommunityRecordId(updatedCommunity) === cachedRecordId;
295
- cachedRecordId = undefined;
296
- if (isCachedRecordReplay) {
450
+ const isRecordReplay = liveCommunity.replayRecordId !== undefined &&
451
+ getCommunityRecordId(updatedCommunity) === liveCommunity.replayRecordId;
452
+ liveCommunity.replayRecordId = undefined;
453
+ if (isRecordReplay && !liveCommunity.replayRefreshesFetchedAt) {
454
+ // a restarted loop replays the record the store already has, it was not fetched now
455
+ return;
456
+ }
457
+ if (isRecordReplay) {
297
458
  // the replayed record is already in the store and the database, only refresh fetchedAt
298
459
  // like a fetched update would, without cloning and rewriting the whole record
299
460
  setState((state) => {
@@ -315,27 +476,26 @@ const communitiesStore = createStore((setState, getState) => ({
315
476
  // add fetchedAt to be able to expire the cache
316
477
  // NOTE: fetchedAt is undefined on owner communities because never stale
317
478
  updatedCommunity.fetchedAt = Math.floor(Date.now() / 1000);
318
- yield communitiesDatabase.setItem(communityKey, updatedCommunity);
479
+ // pkc-js reports the fetch succeeded right after this event, so store the record first:
480
+ // a succeeded sync state must not be shown with the previous record, e.g. a stale one
481
+ // kept while the community was not updating
482
+ setState((state) => (Object.assign(Object.assign({}, state), { communities: Object.assign(Object.assign({}, state.communities), { [communityKey]: updatedCommunity }) })));
319
483
  log("communitiesStore community update", {
320
484
  communityAddressOrRef,
321
485
  communityKey,
322
486
  updatedCommunity,
323
487
  account,
324
488
  });
325
- setState((state) => (Object.assign(Object.assign({}, state), { communities: Object.assign(Object.assign({}, state.communities), { [communityKey]: updatedCommunity }) })));
489
+ yield communitiesDatabase.setItem(communityKey, updatedCommunity);
326
490
  // if a community has a role with an account's address add it to the account.communities
327
491
  accountsStore
328
492
  .getState()
329
493
  .accountsActionsInternal.addCommunityRoleToAccountsCommunities(updatedCommunity);
330
494
  // add page comments to communitiesPagesStore so they can be used in useComment
331
495
  communitiesPagesStore.getState().addCommunityPageCommentsToStore(updatedCommunity);
496
+ endOpeningCommunityUpdate(communityKey, liveCommunity);
332
497
  }));
333
- community.on("updatingstatechange", (updatingState) => {
334
- setState((state) => ({
335
- syncStatuses: getNextSyncStatuses(state, communityKey, normalizeCommunitySyncState(updatingState)),
336
- communities: Object.assign(Object.assign({}, state.communities), { [communityKey]: Object.assign(Object.assign({}, state.communities[communityKey]), { updatingState }) }),
337
- }));
338
- });
498
+ community.on("updatingstatechange", liveCommunity.onUpdatingStateChange);
339
499
  community.on("error", (error) => {
340
500
  scheduleCommunityError(setState, communityKey, error);
341
501
  });
@@ -362,7 +522,13 @@ const communitiesStore = createStore((setState, getState) => ({
362
522
  });
363
523
  });
364
524
  listeners.push(community);
365
- startCommunityUpdatePolling(community, { communityAddressOrRef, communityKey });
525
+ liveCommunities[communityKey] = liveCommunity;
526
+ startCommunityUpdatePolling(communityKey, liveCommunity);
527
+ // loaded without a subscriber, e.g. by a store-level caller: update until the grace period
528
+ // ends, and at least until the first fetch ends
529
+ if (!hasCommunityUpdateSubscribers(communityKey)) {
530
+ scheduleCommunityUpdateStop(communityKey);
531
+ }
366
532
  }
367
533
  catch (error) {
368
534
  updateCommunitySyncStatus(setState, communityKey, "failed");
@@ -373,6 +539,44 @@ const communitiesStore = createStore((setState, getState) => ({
373
539
  }
374
540
  });
375
541
  },
542
+ // keep a community updating while a subscriber (a mounted hook or feed) needs it, and restart
543
+ // its update loop if it stopped after its previous subscribers left
544
+ startCommunityAutoUpdate(communityAddressOrRef, subscriberId, account) {
545
+ return __awaiter(this, void 0, void 0, function* () {
546
+ const communityKey = getCommunityKey(communityAddressOrRef);
547
+ assert(communityKey !== "" && typeof communityKey === "string", `communitiesStore.startCommunityAutoUpdate invalid communityAddress argument '${communityAddressOrRef}'`);
548
+ assert(subscriberId && typeof subscriberId === "string", `communitiesStore.startCommunityAutoUpdate invalid subscriberId argument '${subscriberId}'`);
549
+ if (!communityUpdateSubscribers[communityKey]) {
550
+ communityUpdateSubscribers[communityKey] = new Set();
551
+ }
552
+ communityUpdateSubscribers[communityKey].add(subscriberId);
553
+ clearCommunityStopTimer(communityKey);
554
+ const liveCommunity = liveCommunities[communityKey];
555
+ if (liveCommunity) {
556
+ liveCommunity.stopWhenOpeningUpdateEnds = false;
557
+ yield resumeCommunityUpdatePolling(communityKey);
558
+ return;
559
+ }
560
+ yield getState().addCommunityToStore(communityAddressOrRef, account);
561
+ });
562
+ },
563
+ // the community stops updating a grace period after its last subscriber leaves
564
+ stopCommunityAutoUpdate(communityAddressOrRef, subscriberId) {
565
+ return __awaiter(this, void 0, void 0, function* () {
566
+ const communityKey = getCommunityKey(communityAddressOrRef);
567
+ const subscribers = communityUpdateSubscribers[communityKey];
568
+ if (!(subscribers === null || subscribers === void 0 ? void 0 : subscribers.delete(subscriberId))) {
569
+ return;
570
+ }
571
+ if (subscribers.size > 0) {
572
+ return;
573
+ }
574
+ delete communityUpdateSubscribers[communityKey];
575
+ if (liveCommunities[communityKey]) {
576
+ scheduleCommunityUpdateStop(communityKey);
577
+ }
578
+ });
579
+ },
376
580
  refreshCommunity(communityAddressOrRef, account) {
377
581
  return __awaiter(this, void 0, void 0, function* () {
378
582
  const communityLookupOptions = getCommunityLookupOptions(communityAddressOrRef);
@@ -487,7 +691,11 @@ export const resetCommunitiesStore = () => __awaiter(void 0, void 0, void 0, fun
487
691
  // remove all event listeners
488
692
  listeners.forEach((listener) => listener.removeAllListeners());
489
693
  listeners.length = 0;
490
- Object.keys(communityUpdatePollers).forEach(stopCommunityUpdatePolling);
694
+ Object.keys(liveCommunities).forEach(stopCommunityUpdatePolling);
695
+ Object.keys(communityStopTimers).forEach(clearCommunityStopTimer);
696
+ for (const communityKey in communityUpdateSubscribers) {
697
+ delete communityUpdateSubscribers[communityKey];
698
+ }
491
699
  // destroy all component subscriptions to the store
492
700
  communitiesStore.destroy();
493
701
  // restore original state