Skip to content

Commit 8539158

Browse files
committed
refactor(cdk-experimental/ui-patterns): remove uses of signal
1 parent 11599f8 commit 8539158

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

src/cdk-experimental/ui-patterns/behaviors/list-navigation/list-navigation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {signal, Signal, WritableSignal} from '@angular/core';
9+
import {Signal, WritableSignal} from '@angular/core';
1010

1111
/** Represents an item in a collection, such as a listbox option, than can be navigated to. */
1212
export interface ListNavigationItem {
@@ -38,16 +38,16 @@ export interface ListNavigationInputs<T extends ListNavigationItem> {
3838
/** Controls navigation for a list of items. */
3939
export class ListNavigation<T extends ListNavigationItem> {
4040
/** The last index that was active. */
41-
prevActiveIndex = signal(0);
41+
prevActiveIndex = 0;
4242

4343
constructor(readonly inputs: ListNavigationInputs<T>) {
44-
this.prevActiveIndex.set(inputs.activeIndex());
44+
this.prevActiveIndex = inputs.activeIndex();
4545
}
4646

4747
/** Navigates to the given item. */
4848
goto(item: T) {
4949
if (this.isFocusable(item)) {
50-
this.prevActiveIndex.set(this.inputs.activeIndex());
50+
this.prevActiveIndex = this.inputs.activeIndex();
5151
const index = this.inputs.items().indexOf(item);
5252
this.inputs.activeIndex.set(index);
5353
}

src/cdk-experimental/ui-patterns/behaviors/list-selection/list-selection.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {signal, Signal, WritableSignal} from '@angular/core';
9+
import {Signal, WritableSignal} from '@angular/core';
1010
import {ListNavigation, ListNavigationItem} from '../list-navigation/list-navigation';
1111

1212
/** Represents an item in a collection, such as a listbox option, than can be selected. */
@@ -36,7 +36,7 @@ export interface ListSelectionInputs<T extends ListSelectionItem> {
3636
/** Controls selection for a list of items. */
3737
export class ListSelection<T extends ListSelectionItem> {
3838
/** The id of the most recently selected item. */
39-
previousSelectedId = signal<string | undefined>(undefined);
39+
previousSelectedId?: string;
4040

4141
/** The navigation controller of the parent list. */
4242
navigation: ListNavigation<T>;
@@ -105,13 +105,13 @@ export class ListSelection<T extends ListSelectionItem> {
105105

106106
/** Selects the items in the list starting at the last selected item. */
107107
selectFromPrevSelectedItem() {
108-
const prevSelectedId = this.inputs.items().findIndex(i => this.previousSelectedId() === i.id());
108+
const prevSelectedId = this.inputs.items().findIndex(i => this.previousSelectedId === i.id());
109109
this._selectFromIndex(prevSelectedId);
110110
}
111111

112112
/** Selects the items in the list starting at the last active item. */
113113
selectFromActive() {
114-
this._selectFromIndex(this.inputs.navigation.prevActiveIndex());
114+
this._selectFromIndex(this.inputs.navigation.prevActiveIndex);
115115
}
116116

117117
/** Selects the items in the list starting at the given index. */
@@ -137,6 +137,6 @@ export class ListSelection<T extends ListSelectionItem> {
137137
/** Sets the anchor to the current active index. */
138138
private _anchor() {
139139
const item = this.inputs.items()[this.inputs.navigation.inputs.activeIndex()];
140-
this.previousSelectedId.set(item.id());
140+
this.previousSelectedId = item.id();
141141
}
142142
}

src/cdk-experimental/ui-patterns/behaviors/list-typeahead/list-typeahead.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {signal, Signal} from '@angular/core';
9+
import {Signal} from '@angular/core';
1010
import {ListNavigationItem, ListNavigation} from '../list-navigation/list-navigation';
1111

1212
/**
@@ -36,10 +36,10 @@ export class ListTypeahead<T extends ListTypeaheadItem> {
3636
navigation: ListNavigation<T>;
3737

3838
/** Keeps track of the characters that typeahead search is being called with. */
39-
private _query = signal('');
39+
private _query = '';
4040

4141
/** The index where that the typeahead search was initiated from. */
42-
private _startIndex = signal<number | undefined>(undefined);
42+
private _startIndex?: number;
4343

4444
constructor(readonly inputs: ListTypeaheadInputs & {navigation: ListNavigation<T>}) {
4545
this.navigation = inputs.navigation;
@@ -51,21 +51,21 @@ export class ListTypeahead<T extends ListTypeaheadItem> {
5151
return;
5252
}
5353

54-
if (this._startIndex() === undefined) {
55-
this._startIndex.set(this.navigation.inputs.activeIndex());
54+
if (this._startIndex === undefined) {
55+
this._startIndex = this.navigation.inputs.activeIndex();
5656
}
5757

5858
clearTimeout(this.timeout);
59-
this._query.update(q => q + char.toLowerCase());
59+
this._query = this._query + char.toLowerCase();
6060
const item = this._getItem();
6161

6262
if (item) {
6363
this.navigation.goto(item);
6464
}
6565

6666
this.timeout = setTimeout(() => {
67-
this._query.set('');
68-
this._startIndex.set(undefined);
67+
this._query = '';
68+
this._startIndex = undefined;
6969
}, this.inputs.typeaheadDelay() * 1000);
7070
}
7171

@@ -74,11 +74,12 @@ export class ListTypeahead<T extends ListTypeaheadItem> {
7474
* current query starting from the the current anchor index.
7575
*/
7676
private _getItem() {
77+
// TODO(wagnermaciel): Reuse the logic in list-navigation to do this.
7778
let items = this.navigation.inputs.items();
78-
const after = items.slice(this._startIndex()! + 1);
79-
const before = items.slice(0, this._startIndex()!);
79+
const after = items.slice(this._startIndex! + 1);
80+
const before = items.slice(0, this._startIndex!);
8081
items = this.navigation.inputs.wrap() ? after.concat(before) : after; // TODO: Always wrap?
81-
items.push(this.navigation.inputs.items()[this._startIndex()!]);
82+
items.push(this.navigation.inputs.items()[this._startIndex!]);
8283

8384
const focusableItems = [];
8485
for (const item of items) {
@@ -87,6 +88,6 @@ export class ListTypeahead<T extends ListTypeaheadItem> {
8788
}
8889
}
8990

90-
return focusableItems.find(i => i.searchTerm().toLowerCase().startsWith(this._query()));
91+
return focusableItems.find(i => i.searchTerm().toLowerCase().startsWith(this._query));
9192
}
9293
}

0 commit comments

Comments
 (0)