Skip to content

Commit

Permalink
Fix issue primefaces#14119 - Migrating mutate function to update func…
Browse files Browse the repository at this point in the history
…tion for WritableSignal updates.
  • Loading branch information
antonionesta committed Nov 18, 2023
1 parent 60e0c93 commit 0896ece
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/app/components/cascadeselect/cascadeselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ export class CascadeSelect implements OnInit, AfterContentInit {

changeFocusedOptionIndex(event, index) {
if (this.focusedOptionInfo().index !== index) {
this.focusedOptionInfo.mutate((value) => (value.index = index));
this.focusedOptionInfo.update((value) => ({...value, index}));
this.scrollInView();
}

Expand Down
25 changes: 14 additions & 11 deletions src/app/components/contextmenu/contextmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,10 +833,11 @@ export class ContextMenu implements OnInit, AfterContentInit, OnDestroy {
onEscapeKey(event: KeyboardEvent) {
this.hide();
const processedItem = this.findVisibleItem(this.findFirstFocusedItemIndex());
this.focusedItemInfo.mutate((value) => {
value.index = this.findFirstFocusedItemIndex();
value.item = processedItem.item;
});
this.focusedItemInfo.update((value) => ({
...value,
index: this.findFirstFocusedItemIndex(),
item: processedItem.item
}));

event.preventDefault();
}
Expand All @@ -863,9 +864,10 @@ export class ContextMenu implements OnInit, AfterContentInit, OnDestroy {
const grouped = this.isProccessedItemGroup(processedItem);

if (!grouped) {
this.focusedItemInfo.mutate((value) => {
value.index = this.findFirstFocusedItemIndex();
});
this.focusedItemInfo.update((value) => ({
...value,
index: this.findFirstFocusedItemIndex()
}));
}
}

Expand Down Expand Up @@ -1086,10 +1088,11 @@ export class ContextMenu implements OnInit, AfterContentInit, OnDestroy {
changeFocusedItemIndex(event: any, index: number) {
const processedItem = this.findVisibleItem(index);
if (this.focusedItemInfo().index !== index) {
this.focusedItemInfo.mutate((value) => {
value.index = index;
value.item = processedItem.item;
});
this.focusedItemInfo.update((value) => ({
...value,
index: index,
item: processedItem.item
}));
this.scrollInView();
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/app/components/megamenu/megamenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -830,11 +830,12 @@ export class MegaMenu implements AfterContentInit, OnDestroy, OnInit {

changeFocusedItemInfo(event, index) {
const processedItem = this.findVisibleItem(index);
this.focusedItemInfo.mutate((value) => {
value.index = index;
value.key = ObjectUtils.isNotEmpty(processedItem) ? processedItem.key : '';
value.item = processedItem.item;
});
this.focusedItemInfo.update((value) => ({
...value,
index: index,
key: ObjectUtils.isNotEmpty(processedItem) ? processedItem.key : '',
item: processedItem.item
}));

this.scrollInView();
}
Expand Down
7 changes: 2 additions & 5 deletions src/app/components/menubar/menubar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,12 +669,9 @@ export class Menubar implements AfterContentInit, OnDestroy, OnInit {
}

changeFocusedItemIndex(event: any, index: number) {
const processedItem = this.findVisibleItem(index);
const { item } = this.findVisibleItem(index);
if (this.focusedItemInfo().index !== index) {
this.focusedItemInfo.mutate((value) => {
value.index = index;
value.item = processedItem.item;
});
this.focusedItemInfo.update((value) => ({...value, index, item }));
this.scrollInView();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/panelmenu/panelmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ export class PanelMenuList implements OnChanges {
expanded && activeItemPath.push(processedItem);

this.activeItemPath.set(activeItemPath);
this.processedItems.mutate((value) => value.map((i) => (i === processedItem ? processedItem : i)));
this.processedItems.update((value) => value.map((i) => (i === processedItem ? processedItem : i)));
this.focusedItem.set(processedItem);
}

Expand Down
51 changes: 25 additions & 26 deletions src/app/components/slidemenu/slidemenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,12 +711,13 @@ export class SlideMenu implements OnInit, AfterContentInit, OnDestroy {
const grouped = this.isProcessedItemGroup(processedItem);

if (grouped) {
this.focusedItemInfo.mutate((value) => {
value.index = -1;
value.level = value.level + 1;
value.parentKey = processedItem.key;
value.item = processedItem.item;
});
this.focusedItemInfo.update((value) => ({
...value,
index: -1,
level: value.level + 1,
parentKey: processedItem.key,
item: processedItem.item
}));
this.animate('right');
} else {
this.onItemChange(event);
Expand Down Expand Up @@ -796,10 +797,7 @@ export class SlideMenu implements OnInit, AfterContentInit, OnDestroy {
case 'Enter':
case 'Space':
this.onArrowLeftKey(event);
this.focusedItemInfo.mutate((value) => {
value.index = -1;
value.item = null;
});
this.focusedItemInfo.update((value) => ({...value, index: -1, item: null }));
break;
default:
break;
Expand Down Expand Up @@ -909,10 +907,11 @@ export class SlideMenu implements OnInit, AfterContentInit, OnDestroy {
onEscapeKey(event: KeyboardEvent) {
if (this.popup) {
this.hide(event, true);
this.focusedItemInfo.mutate((value) => {
value.index = this.findLastFocusedItemIndex();
value.item = null;
});
this.focusedItemInfo.update((value) => ({
...value,
index: this.findLastFocusedItemIndex(),
item: null
}));

event.preventDefault();
}
Expand Down Expand Up @@ -941,10 +940,11 @@ export class SlideMenu implements OnInit, AfterContentInit, OnDestroy {
const anchorElement = element && DomHandler.findSingle(element, 'a[data-pc-section="action"]');

anchorElement ? anchorElement.click() : element && element.click();
this.focusedItemInfo.mutate((value) => {
value.index = processedItem.index;
value.item = processedItem.item;
});
this.focusedItemInfo.update((value) => ({
...value,
index: processedItem.index,
item: processedItem.item
}));
}
}

Expand Down Expand Up @@ -976,7 +976,7 @@ export class SlideMenu implements OnInit, AfterContentInit, OnDestroy {
}

if (this.focusedItemInfo().index === -1 && this.left < 0) {
this.focusedItemInfo.mutate((value) => (value.index = 0));
this.focusedItemInfo.update((value) => ({...value, index: 0}));
}

if (this.focusedItemInfo().index === -1 && !this.left) {
Expand All @@ -988,10 +988,11 @@ export class SlideMenu implements OnInit, AfterContentInit, OnDestroy {
this.focused = false;
this.popup && this.focusedItemInfo.set({ index: -1, level: 0, parentKey: '', item: null });
if (!this.popup) {
this.focusedItemInfo.mutate((value) => {
value.index = -1;
value.item = null;
});
this.focusedItemInfo.update((value) => ({
...value,
index: -1,
item: null
}));
}
this.searchValue = '';
!this.popup && this.unbindOutsideClickListener();
Expand Down Expand Up @@ -1217,9 +1218,7 @@ export class SlideMenu implements OnInit, AfterContentInit, OnDestroy {

changeFocusedItemIndex(event: any, index: number) {
if (this.focusedItemInfo().index !== index) {
this.focusedItemInfo.mutate((value) => {
value.index = index;
});
this.focusedItemInfo.update((value) => ({...value, index}));
this.scrollInView();
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/app/components/tieredmenu/tieredmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1064,10 +1064,7 @@ export class TieredMenu implements OnInit, AfterContentInit, OnDestroy {

changeFocusedItemIndex(event: any, index: number) {
if (this.focusedItemInfo().index !== index) {
this.focusedItemInfo.mutate((value) => {
value.index = index;
value.item = this.visibleItems[index].item;
});
this.focusedItemInfo.update((value) => ({ ...value, index, item: this.visibleItems[index].item }));
this.scrollInView();
}
}
Expand Down

0 comments on commit 0896ece

Please sign in to comment.