Skip to content

Commit

Permalink
[Angular] Migrate to signals (sort-by.directive.ts)
Browse files Browse the repository at this point in the history
  • Loading branch information
qmonmert committed Dec 16, 2024
1 parent 5e15bfa commit 3df8768
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class SortByDirective {
effect(() => {
if (this.iconComponent()) {
let icon: IconDefinition = this.sortIcon;
const { predicate, order } = this.sort.sortState();
const { predicate, order } = this.sort.sortState()();
if (predicate === this.<%= jhiPrefix %>SortBy() && order !== undefined) {
icon = order === 'asc' ? this.sortAscIcon : this.sortDescIcon;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
import { Directive, EventEmitter, Input, Output } from '@angular/core';
import { Directive, input, output, OutputEmitterRef } from '@angular/core';
import { SortOrder, SortState, SortStateSignal } from './sort-state';

export interface SortChangeDirective<T> {
sortChange: EventEmitter<SortState>;
sortChange: OutputEmitterRef<SortState>;

sort(field: T): void;
}
Expand All @@ -29,12 +29,12 @@ export interface SortChangeDirective<T> {
selector: '[<%= jhiPrefix %>Sort]',
})
export class SortDirective implements SortChangeDirective<string> {
@Input() sortState!: SortStateSignal;
readonly sortState = input.required<SortStateSignal>();

@Output() sortChange = new EventEmitter<SortState>();
readonly sortChange = output<SortState>();

sort(field: string): void {
const { predicate, order } = this.sortState();
const { predicate, order } = this.sortState()();
const toggle = (): SortOrder => (order === 'asc' ? 'desc' : 'asc');
this.sortChange.emit({ predicate: field, order: field !== predicate ? 'asc' : toggle() });
}
Expand Down

0 comments on commit 3df8768

Please sign in to comment.