Skip to content

Commit

Permalink
refactor(kit): drop async pipe in TuiTreeItemContent
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Sep 29, 2024
1 parent 8cce7ee commit 248b03f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {AsyncPipe, NgIf, NgTemplateOutlet} from '@angular/common';
import {NgIf, NgTemplateOutlet} from '@angular/common';
import type {DoCheck} from '@angular/core';
import {ChangeDetectionStrategy, Component, forwardRef, inject} from '@angular/core';
import {toSignal} from '@angular/core/rxjs-interop';
import {TuiButton} from '@taiga-ui/core/components/button';
import {TUI_COMMON_ICONS} from '@taiga-ui/core/tokens';
import {injectContext} from '@taiga-ui/polymorpheus';
Expand All @@ -12,7 +13,7 @@ import {TUI_TREE_CONTROLLER} from '../../misc/tree.tokens';

@Component({
standalone: true,
imports: [AsyncPipe, NgIf, NgTemplateOutlet, TuiButton],
imports: [NgIf, NgTemplateOutlet, TuiButton],
templateUrl: './tree-item-content.template.html',
styleUrls: ['./tree-item-content.style.less'],
changeDetection: ChangeDetectionStrategy.OnPush,
Expand All @@ -30,10 +31,13 @@ export class TuiTreeItemContent implements DoCheck {
protected readonly icons = inject(TUI_COMMON_ICONS);
protected readonly context = injectContext<TuiTreeItemContext>();

protected readonly expanded$ = this.change$.pipe(
startWith(null),
map(() => this.isExpanded),
distinctUntilChanged(),
protected readonly expanded = toSignal(
this.change$.pipe(
startWith(null),
map(() => this.isExpanded),
distinctUntilChanged(),
),
{initialValue: this.isExpanded},
);

public ngDoCheck(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
tuiIconButton
type="button"
class="t-button"
[class.t-button_expanded]="expanded$ | async"
[class.t-button_expanded]="expanded()"
[iconStart]="icons.more"
[style.border-radius.%]="100"
(click)="onClick()"
Expand Down

0 comments on commit 248b03f

Please sign in to comment.