Skip to content

Commit

Permalink
refactor: enforce readonly signals
Browse files Browse the repository at this point in the history
  • Loading branch information
Javier Marín committed Dec 10, 2024
1 parent 850777d commit fa4452e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,26 @@ export class NgTalkBubbleChannelComponent {
@Input() public user: ChatUser;
@Input() public selfRef: BubbleChannelRef;

private _bubbleElement = viewChild.required('bubble', {read: ElementRef<HTMLElement>});
private _ngTalkChannel = viewChild.required(NgTalkChannelComponent);
private _closeButton = viewChild('closeButton', {read: ElementRef<HTMLElement>});
private readonly _bubbleElement = viewChild.required('bubble', {read: ElementRef<HTMLElement>});
private readonly _ngTalkChannel = viewChild.required(NgTalkChannelComponent);
private readonly _closeButton = viewChild('closeButton', {read: ElementRef<HTMLElement>});

protected bubbleClass = signal('');
protected readonly bubbleClass = signal('');

protected channelVisible = signal(false);
protected channelClass = signal('bounceIn');
protected readonly channelVisible = signal(false);
protected readonly channelClass = signal('bounceIn');
protected channelStyle: { [key: string]: string | number } = {display: 'none'};

protected dragPosition = signal<{ x: number; y: number; }>(null);
protected readonly dragPosition = signal<{ x: number; y: number; }>(null);

protected isOverCloseBtn = computed(() => {
protected readonly isOverCloseBtn = computed(() => {
if (this.dragPosition() && this._closeButton()) {
return this._isOver(this.dragPosition().x, this.dragPosition().y, this._closeButton().nativeElement, 20);
} else {
return false;
}
});
protected closeBtnAnimationClass = signal('');
protected readonly closeBtnAnimationClass = signal('');

private _documentClickSubscription: Subscription;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class NgTalkChannelListComponent implements OnInit, OnChanges, OnDestroy
// State
public activeChannel: ChatChannel;
private _channelsSubscription: Subscription;
protected channels = signal<ChatChannel[]>(null);
protected readonly channels = signal<ChatChannel[]>(null);

private _channelMessagesSubscriptions = new Map<string, Subscription>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class NgTalkChannelMessageComponent implements OnChanges, OnDestroy {
@Input() public prevMessage: ChatMessage;

// State
private _toolsMenu = viewChild(MatMenuTrigger);
private readonly _toolsMenu = viewChild(MatMenuTrigger);

@HostBinding('class') private _className: string;
protected showAuthor = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export class NgTalkChannelComponent implements OnInit, OnChanges, AfterViewInit
public readonly deleted = output<void>();

// State
private _chatBox = viewChild('chatBox', {read: ElementRef<HTMLElement>});
private _sendMessageComponent = viewChild(NgTalkSendMessageComponent);
private _messageComponents = viewChildren(NgTalkChannelMessageComponent);
private readonly _chatBox = viewChild('chatBox', {read: ElementRef<HTMLElement>});
private readonly _sendMessageComponent = viewChild(NgTalkSendMessageComponent);
private readonly _messageComponents = viewChildren(NgTalkChannelMessageComponent);

private _visibleMessages = 20;
public readonly messages = signal<ChatMessage[]>([]);
Expand All @@ -70,8 +70,8 @@ export class NgTalkChannelComponent implements OnInit, OnChanges, AfterViewInit
public replyingTo: ChatMessage;

// UI
protected loading = signal(false);
protected scrollWatcherEnabled = signal(false);
protected readonly loading = signal(false);
protected readonly scrollWatcherEnabled = signal(false);
protected readonly viewportDetectionAvailable = InViewportDirective.intersectionObserverFeatureDetection();

// Import types and enums
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class NgTalkSendGifComponent implements OnInit {

// State
protected searchQuery: string;
protected gifs$ = signal<Observable<any>>(null);
protected readonly gifs$ = signal<Observable<any>>(null);

private _deBouncer: Subject<string>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import {growAnimation} from './grow-animation';
export class NgTalkSendMessageComponent {
protected readonly chat = inject(NgTalkChannelComponent);

private _textInput = viewChild('textInput', {read: ElementRef<HTMLInputElement>});
private readonly _textInput = viewChild('textInput', {read: ElementRef<HTMLInputElement>});

protected newMessage = '';
protected mediaSelector: string = null;
Expand Down
2 changes: 1 addition & 1 deletion projects/ng-talk/src/lib/service/bubble-channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {NgTalkBubbleChannelComponent} from "../components/bubble/ng-talk-bubble-
providedIn: 'root'
})
export class BubbleChannelService {
private static _activeInstances = signal<BubbleChannelRef[]>([]);
private static readonly _activeInstances = signal<BubbleChannelRef[]>([]);

// Deps
private _appRef = inject(ApplicationRef);
Expand Down

0 comments on commit fa4452e

Please sign in to comment.