Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure stable sort #1130

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/client/src/store/CallState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,9 @@ export class CallState {
constructor() {
this.logger = getLogger(['CallState']);
this.participants$ = this.participantsSubject.asObservable().pipe(
// TODO: replace with Array.toSorted once available
map((ps) => [...ps].sort(this.sortParticipantsBy)),
// maintain stable-sort by mutating the participants stored
// in the original subject
map((ps) => ps.sort(this.sortParticipantsBy)),
shareReplay({ bufferSize: 1, refCount: true }),
);

Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/store/__tests__/CallState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('CallState', () => {

const ps2 = state.participants;
// should resolve in initial - non-mutated state as set at the beginning
expect(ps2.map((p) => p.name)).toEqual(['A', 'B', 'C', 'D', 'E', 'F']);
expect(ps2.map((p) => p.name)).toEqual(['F', 'B', 'E', 'A', 'C', 'D']);
Copy link
Contributor

@arnautov-anton arnautov-anton Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(ps2.map((p) => p.name)).toEqual(['F', 'B', 'E', 'A', 'C', 'D']);
expect(ps2.map((p) => p.name)).toMatchInlineSnapshot(...);

Can we do .toMatchInlineSnapshot instead (like here)? The outputs that vitest gives when it compares arrays is super unreadable and updating it manually is super annoying (not that we should do that often but still).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather do that at some other time. There are plenty of places we would need to align.

});

it('should support custom sorting', () => {
Expand Down
Loading