Skip to content

Commit

Permalink
refactor: replace @output decorator with output() function
Browse files Browse the repository at this point in the history
  • Loading branch information
javiermarinros committed Mar 15, 2024
1 parent 393001e commit 408aad8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import {
Component,
DestroyRef,
ElementRef,
EventEmitter,
forwardRef,
HostBinding,
HostListener,
Input,
OnChanges,
OnDestroy,
OnInit,
Output,
output,
signal,
SimpleChanges
} from '@angular/core';
Expand All @@ -25,10 +24,10 @@ import {ChatMessage} from '../../models/chat-message';
import {ChatUser} from '../../models/chat-user';
import {FnPipe} from "../../pipes/fn.pipe";
import {nameof} from '../../utils/utils';
import {NgTalkChannelComponent} from "../channel/ng-talk-channel.component";
import {NgTalkChannelPreviewComponent} from "../channel/preview/ng-talk-channel-preview.component";
import {MessageLoadingMethod, NgTalkSettings} from '../ng-talk-settings';
import {NG_TALK_CHANNEL_LIST_TOKEN} from "./ng-talk-channel-list-token";
import {NgTalkChannelPreviewComponent} from "../channel/preview/ng-talk-channel-preview.component";
import {NgTalkChannelComponent} from "../channel/ng-talk-channel.component";

@Component({
selector: 'ng-talk-channel-list',
Expand All @@ -46,12 +45,12 @@ export class NgTalkChannelListComponent implements OnInit, OnChanges, OnDestroy
@Input() public user: ChatUser;
@Input() public adapter: ChatAdapter;
@Input() public settings = new NgTalkSettings();
@Output() public search = new EventEmitter<string>();
@Output() public channelChanged = new EventEmitter<ChatChannel | null>();
public search = output<string>();
public channelChanged = output<ChatChannel | null>();

// Forwarded events from single channel
@Output() public messageSent = new EventEmitter<ChatMessage>();
@Output() public userClicked = new EventEmitter<ChatUser>();
public messageSent = output<ChatMessage>();
public userClicked = output<ChatUser>();

@HostBinding('class')
public displayMode: 'desktop' | 'mobile';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {CdkDrag, CdkDragEnd, CdkDragMove} from '@angular/cdk/drag-drop';
import {NgComponentOutlet} from "@angular/common";
import {AfterViewInit, Component, DestroyRef, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output, signal, SimpleChanges, ViewChild, viewChildren} from '@angular/core';
import {AfterViewInit, Component, DestroyRef, ElementRef, Input, OnChanges, OnInit, output, signal, SimpleChanges, ViewChild, viewChildren} from '@angular/core';
import {takeUntilDestroyed} from "@angular/core/rxjs-interop";
import {Subscription} from 'rxjs';
import {InViewportDirective} from '../../directives/in-viewport.directive';
Expand Down Expand Up @@ -35,9 +35,9 @@ export class NgTalkChannelComponent implements OnInit, OnChanges, AfterViewInit
@Input() public settings: NgTalkSettings;
@Input() public disableRendering = false;

@Output() public messageSent = new EventEmitter<ChatMessage>();
@Output() public userClicked = new EventEmitter<ChatUser>();
@Output() public deleted = new EventEmitter<void>();
public messageSent = output<ChatMessage>();
public userClicked = output<ChatUser>();
public deleted = output<void>();

@ViewChild('chatBox') private _chatBox: ElementRef<HTMLElement>;
@ViewChild(NgTalkSendMessageComponent) private _sendMessageComponent: NgTalkSendMessageComponent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {KeyValue, KeyValuePipe} from '@angular/common';
import {Component, EventEmitter, Output} from '@angular/core';
import {Component, output} from '@angular/core';
import {FormsModule} from "@angular/forms";
import {FnPipe} from "../../../../pipes/fn.pipe";
import {NgTalkChannelComponent} from '../../ng-talk-channel.component';
Expand Down Expand Up @@ -52,7 +52,7 @@ import emoji from './emoji.json';
`
})
export class NgTalkSendEmojiComponent {
@Output() public emojiSelected = new EventEmitter<string>();
public emojiSelected = output<string>();

protected readonly emoji = emoji;
protected searchQuery: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {AsyncPipe} from "@angular/common";
import {HttpClient} from '@angular/common/http';
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {Component, OnInit, output} from '@angular/core';
import {FormsModule} from "@angular/forms";
import {debounceTime, map, Observable, Subject} from 'rxjs';
import {FnPipe} from "../../../../pipes/fn.pipe";
Expand Down Expand Up @@ -57,7 +57,7 @@ import {NgTalkChannelComponent} from '../../ng-talk-channel.component';
`
})
export class NgTalkSendGifComponent implements OnInit {
@Output() public gifSelected = new EventEmitter<string>();
public gifSelected = output<string>();

protected searchQuery: string;
protected gifs$: Observable<any>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Component, ElementRef, Inject, Optional, ViewChild} from '@angular/core';
import {takeUntilDestroyed} from "@angular/core/rxjs-interop";
import {Component, DestroyRef, ElementRef, Inject, Optional, ViewChild} from '@angular/core';
import {FormsModule} from "@angular/forms";
import {ChatChannel} from '../../../models/chat-channel';
import {ChatMessage, ChatMessageType} from '../../../models/chat-message';
Expand Down Expand Up @@ -144,9 +143,11 @@ export class NgTalkSendMessageComponent {
protected showGifSelector = false;

constructor(protected chat: NgTalkChannelComponent,
destroyRef: DestroyRef,
@Optional() @Inject(NG_TALK_CHANNEL_LIST_TOKEN) channelList: NgTalkChannelListComponent) {
if (channelList) { // Detectar cambio de canal si estamos en un listado
channelList.channelChanged.pipe(takeUntilDestroyed()).subscribe((c) => this._onChannelChanged(c));
const subscription = channelList.channelChanged.subscribe((c) => this._onChannelChanged(c));
destroyRef.onDestroy(() => subscription.unsubscribe());
}

chat.focus = () => this.focus();
Expand Down
4 changes: 2 additions & 2 deletions projects/ng-talk/src/lib/directives/in-viewport.directive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Directive, ElementRef, EventEmitter, Input, OnDestroy, OnInit, Output} from '@angular/core';
import {Directive, ElementRef, Input, OnDestroy, OnInit, output} from '@angular/core';

/**
* From https://github.com/thisissoon/angular-inviewport
Expand All @@ -25,7 +25,7 @@ import {Directive, ElementRef, EventEmitter, Input, OnDestroy, OnInit, Output} f
})
export class InViewportDirective implements OnDestroy, OnInit {
@Input() public inViewportOptions: IntersectionObserverInit & { delay?: number };
@Output() public inViewportChange = new EventEmitter<boolean>();
public inViewportChange = output<boolean>();

private _inViewport: boolean;
protected observer: IntersectionObserver;
Expand Down

0 comments on commit 408aad8

Please sign in to comment.