mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 23:16:21 +00:00
Pilot: move InfoStand event listeners to useAvatarInfoWidget owner
InfoStandWidgetUserView previously subscribed to three room-session events (RSUBE_BADGES, USER_FIGURE, FAVOURITE_GROUP_UPDATE) and pushed the result back to its parent via a setAvatarInfo prop, with each handler running CloneObject(prev) before patching one field. Three issues with that shape: - CloneObject was deep-cloning the whole AvatarInfoUser shape blindly with no class-prototype awareness; - the three listeners raced on shallow merges across the same prev reference in StrictMode dev; - the subscriptions lived outside the state owner, forcing a prop callback barrier per event. The subscriptions are now in useAvatarInfoWidget — the actual owner of avatarInfo — and call three pure reducers extracted to src/hooks/rooms/widgets/avatarInfo.reducers.ts (applyUserBadgesUpdate, applyUserFigureUpdate, applyFavouriteGroupUpdate). Each reducer returns the same reference when the event doesn't apply so React bail-outs work. The clone now constructs a fresh AvatarInfoUser preserving prototype. dedupeBadges is extracted to its own pure module under src/api/avatar/ so Vitest can cover it without pulling in the renderer. InfoStandWidgetUserView loses the setAvatarInfo prop (parent updated) and the CloneObject import.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Strips duplicate badge codes from a server-supplied badge array,
|
||||
* preserving slot indices: a duplicate is replaced by an empty string
|
||||
* rather than shifted out, so badge[i] still corresponds to slot i.
|
||||
*
|
||||
* Empty / falsy entries are normalized to '' (some servers emit null
|
||||
* inside the array for unused slots).
|
||||
*/
|
||||
export const dedupeBadges = (badges: ReadonlyArray<string>): string[] =>
|
||||
{
|
||||
const seen = new Set<string>();
|
||||
|
||||
return badges.map(code =>
|
||||
{
|
||||
if(!code || seen.has(code)) return '';
|
||||
|
||||
seen.add(code);
|
||||
|
||||
return code;
|
||||
});
|
||||
};
|
||||
@@ -3,5 +3,6 @@ export * from './AvatarEditorColorSorter';
|
||||
export * from './AvatarEditorPartSorter';
|
||||
export * from './AvatarEditorThumbnailsHelper';
|
||||
export * from './BuildPurchasableClothingFigure';
|
||||
export * from './dedupeBadges';
|
||||
export * from './IAvatarEditorCategory';
|
||||
export * from './IAvatarEditorCategoryPartItem';
|
||||
|
||||
Reference in New Issue
Block a user