@banta/sdk 4.7.11 → 4.7.12

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,9 +1,9 @@
1
1
  import { Observable, Subject, BehaviorSubject, Subscription } from 'rxjs';
2
2
  import { publish, take } from 'rxjs/operators';
3
3
  import * as i0 from '@angular/core';
4
- import { Component, Input, ViewChild, Pipe, Inject, Optional, Output, HostBinding, NgModule, ViewChildren, Directive, TemplateRef, ContentChild, Injectable } from '@angular/core';
4
+ import { Component, Input, ViewChild, Pipe, Inject, Optional, Output, HostBinding, NgModule, ViewChildren, Directive, TemplateRef, ContentChild, Injectable as Injectable$1 } from '@angular/core';
5
5
  import * as i1 from 'projects/sdk/src/lib/common/timer-pool.service';
6
- import { TimerPool } from 'projects/sdk/src/lib/common/timer-pool.service';
6
+ import { TimerPool as TimerPool$1 } from 'projects/sdk/src/lib/common/timer-pool.service';
7
7
  import * as i2 from '@angular/common';
8
8
  import { CommonModule } from '@angular/common';
9
9
  import * as i2$1 from '@angular/material/icon';
@@ -17,6 +17,9 @@ import * as i4 from '@angular/material/progress-spinner';
17
17
  import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
18
18
  import * as i6 from '@angular/material/button';
19
19
  import { MatButtonModule } from '@angular/material/button';
20
+ import { __decorate } from 'tslib';
21
+ import * as i1$3 from '@banta/common';
22
+ import { Injectable, CommentsOrder, SocketRPC, RpcEvent, DurableSocket } from '@banta/common';
20
23
  import * as i4$1 from '@angular/forms';
21
24
  import { FormsModule } from '@angular/forms';
22
25
  import * as i6$1 from '@angular/material/form-field';
@@ -33,8 +36,6 @@ import * as i7$1 from '@angular/material/menu';
33
36
  import { MatMenuModule } from '@angular/material/menu';
34
37
  import * as i11 from '@angular/material/tooltip';
35
38
  import { MatTooltipModule } from '@angular/material/tooltip';
36
- import * as i1$3 from '@banta/common';
37
- import { CommentsOrder, SocketRPC, RpcEvent, DurableSocket } from '@banta/common';
38
39
  import * as i2$3 from '@angular/router';
39
40
  import * as i3$3 from '@angular/material/snack-bar';
40
41
  import { MatSnackBarModule } from '@angular/material/snack-bar';
@@ -43,7 +44,6 @@ import { TextFieldModule } from '@angular/cdk/text-field';
43
44
  import * as i2$2 from '@angular/material/select';
44
45
  import { MatSelectModule } from '@angular/material/select';
45
46
  import * as i3$2 from '@angular/material/core';
46
- import { __decorate } from 'tslib';
47
47
 
48
48
  function lazyConnection(options) {
49
49
  let obs = new Observable(observer => {
@@ -513,6 +513,86 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImpo
513
513
  type: Output
514
514
  }] } });
515
515
 
516
+ /**
517
+ * Provides a way to hook in to a shared set of timers, instead of creating a timer per instance.
518
+ * This is very useful for cases where the update is not extremely time-sensitive, but happens at scale.
519
+ * The principal use case is the TimestampComponent. When several hundred (or several thousand) comments are
520
+ * being displayed, we do not want to trigger thousands of independent relative timestamp updates, because over
521
+ * time the updates will saturate the CPU since they don't perfectly align.
522
+ */
523
+ let TimerPool = class TimerPool {
524
+ constructor() {
525
+ this.subscriptions = new Map();
526
+ this.newSubscriptions = new Map();
527
+ this.removedSubscriptions = new Map();
528
+ }
529
+ addTimer(interval, callback) {
530
+ if (interval <= 0) {
531
+ console.warn(`Refusing to set timer with interval of ${interval}!`);
532
+ return () => { };
533
+ }
534
+ let state;
535
+ let sizeWas = this.subscriptions.size;
536
+ if (!this.subscriptions.has(interval)) {
537
+ state = { subscribers: [] };
538
+ state.handle = setInterval(() => {
539
+ console.debug(`[Banta/TimerPool] Notifying ${state.subscribers.length} subs [${interval}ms]`);
540
+ state.subscribers.forEach(sub => sub());
541
+ }, interval);
542
+ this.subscriptions.set(interval, state);
543
+ }
544
+ else {
545
+ state = this.subscriptions.get(interval);
546
+ }
547
+ state.subscribers.push(callback);
548
+ // Debug information //////////////////////////
549
+ //
550
+ if (!this.newSubscriptions.has(interval))
551
+ this.newSubscriptions.set(interval, 0);
552
+ this.newSubscriptions.set(interval, (this.newSubscriptions.get(interval) ?? 0) + 1);
553
+ clearTimeout(this.newSubscriptionsNotice);
554
+ this.newSubscriptionsNotice = setTimeout(() => {
555
+ for (let [interval, count] of this.newSubscriptions) {
556
+ console.debug(`[Banta/TimerPool] ${count} new subscriptions to ${interval}ms [${state.subscribers.length} total]`);
557
+ }
558
+ this.newSubscriptions.clear();
559
+ });
560
+ //
561
+ ///////////////////////////////////////////////
562
+ if (sizeWas === 0) {
563
+ console.debug(`[Banta/TimerPool] No longer idle.`);
564
+ }
565
+ // Unsubscribe function
566
+ return () => {
567
+ let state = this.subscriptions.get(interval);
568
+ let index = state.subscribers.indexOf(callback);
569
+ if (index >= 0)
570
+ state.subscribers.splice(index, 1);
571
+ if (state.subscribers.length === 0) {
572
+ clearInterval(state.handle);
573
+ this.subscriptions.delete(interval);
574
+ }
575
+ if (!this.removedSubscriptions.has(interval))
576
+ this.removedSubscriptions.set(interval, 0);
577
+ this.removedSubscriptions.set(interval, (this.removedSubscriptions.get(interval) ?? 0) + 1);
578
+ // Debug information ////////////////////////////////////////////////////////////////////
579
+ clearTimeout(this.removedSubscriptionsNotice);
580
+ this.removedSubscriptionsNotice = setTimeout(() => {
581
+ for (let [interval, count] of this.removedSubscriptions) {
582
+ let state = this.subscriptions.get(interval);
583
+ console.debug(`[Banta/TimerPool] ${count} unsubscribed from ${interval}ms [${state?.subscribers?.length ?? 0} remain]`);
584
+ }
585
+ if (this.subscriptions.size === 0)
586
+ console.debug(`[Banta/TimerPool] All subscriptions have been removed. Now idle.`);
587
+ this.removedSubscriptions.clear();
588
+ });
589
+ };
590
+ }
591
+ };
592
+ TimerPool = __decorate([
593
+ Injectable()
594
+ ], TimerPool);
595
+
516
596
  const COMPONENTS$3 = [
517
597
  TimestampComponent,
518
598
  LightboxComponent,
@@ -527,7 +607,7 @@ class BantaCommonModule {
527
607
  return {
528
608
  ngModule: BantaCommonModule,
529
609
  providers: [
530
- TimerPool
610
+ TimerPool$1
531
611
  ]
532
612
  };
533
613
  }
@@ -10354,7 +10434,7 @@ class ChatBackend extends ChatBackendBase {
10354
10434
  ChatBackend.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: ChatBackend, deps: [{ token: BANTA_SDK_OPTIONS }], target: i0.ɵɵFactoryTarget.Injectable });
10355
10435
  ChatBackend.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: ChatBackend });
10356
10436
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: ChatBackend, decorators: [{
10357
- type: Injectable
10437
+ type: Injectable$1
10358
10438
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
10359
10439
  type: Inject,
10360
10440
  args: [BANTA_SDK_OPTIONS]
@@ -10396,7 +10476,7 @@ class UrlAttachmentResolver {
10396
10476
  UrlAttachmentResolver.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: UrlAttachmentResolver, deps: [{ token: ChatBackendBase }], target: i0.ɵɵFactoryTarget.Injectable });
10397
10477
  UrlAttachmentResolver.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: UrlAttachmentResolver });
10398
10478
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: UrlAttachmentResolver, decorators: [{
10399
- type: Injectable
10479
+ type: Injectable$1
10400
10480
  }], ctorParameters: function () { return [{ type: ChatBackendBase }]; } });
10401
10481
 
10402
10482
  class YouTubeAttachmentResolver {
@@ -10577,5 +10657,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImpo
10577
10657
  * Generated bundle index. Do not edit.
10578
10658
  */
10579
10659
 
10580
- export { AttachmentButtonComponent, AttachmentScraperDirective, BANTA_SDK_OPTIONS, BantaAttachmentComponent, BantaAttachmentsComponent, BantaChatComponent, BantaCommentsComponent, BantaCommonModule, BantaComponent, BantaLogoComponent, BantaMarkdownToHtmlPipe, BantaMentionLinkerPipe, BantaReplySendOptionsDirective, BantaSdkModule, BantaTrustResourceUrlPipe, ChatBackend, ChatBackendBase, ChatMessageComponent, ChatModule, ChatSource, ChatViewComponent, CommentComponent, CommentFieldComponent, CommentSortComponent, CommentViewComponent, CommentsModule, EMOJIS, EmojiModule, EmojiSelectorButtonComponent, EmojiSelectorPanelComponent, GiphyAttachmentResolver, LightboxComponent, LiveChatMessageComponent, LiveCommentComponent, LiveMessageComponent, TimestampComponent, TweetAttachmentResolver, UrlAttachmentResolver, UrlAttachmentScraper, YouTubeAttachmentResolver, lazyConnection };
10660
+ export { AttachmentButtonComponent, AttachmentScraperDirective, BANTA_SDK_OPTIONS, BantaAttachmentComponent, BantaAttachmentsComponent, BantaChatComponent, BantaCommentsComponent, BantaCommonModule, BantaComponent, BantaLogoComponent, BantaMarkdownToHtmlPipe, BantaMentionLinkerPipe, BantaReplySendOptionsDirective, BantaSdkModule, BantaTrustResourceUrlPipe, ChatBackend, ChatBackendBase, ChatMessageComponent, ChatModule, ChatSource, ChatViewComponent, CommentComponent, CommentFieldComponent, CommentSortComponent, CommentViewComponent, CommentsModule, EMOJIS, EmojiModule, EmojiSelectorButtonComponent, EmojiSelectorPanelComponent, GiphyAttachmentResolver, LightboxComponent, LiveChatMessageComponent, LiveCommentComponent, LiveMessageComponent, TimerPool, TimestampComponent, TweetAttachmentResolver, UrlAttachmentResolver, UrlAttachmentScraper, YouTubeAttachmentResolver, lazyConnection };
10581
10661
  //# sourceMappingURL=banta-sdk.mjs.map