Skip to content

Commit

Permalink
fix(core): rename the equality function option in toSignal (#56769)
Browse files Browse the repository at this point in the history
The option introduced in 5df3e78 has been named `equals` whereas the existing option in `signal` is named `equal`.
This commit renames the new option to `equal` as well to keep the naming coherent across these APIs.

PR Close #56769
  • Loading branch information
cexbrayat authored and atscott committed Jul 8, 2024
1 parent d5ce323 commit 5dcdbfc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion goldens/public-api/core/rxjs-interop/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function toSignal<T, const U extends T>(source: Observable<T> | Subscriba

// @public
export interface ToSignalOptions<T> {
equals?: ValueEqualityFn<T>;
equal?: ValueEqualityFn<T>;
initialValue?: unknown;
injector?: Injector;
manualCleanup?: boolean;
Expand Down
6 changes: 3 additions & 3 deletions packages/core/rxjs-interop/src/to_signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export interface ToSignalOptions<T> {
*
* Equality comparisons are executed against the initial value if one is provided.
*/
equals?: ValueEqualityFn<T>;
equal?: ValueEqualityFn<T>;
}

// Base case: no options -> `undefined` in the result type.
Expand Down Expand Up @@ -147,7 +147,7 @@ export function toSignal<T, U = undefined>(
? options?.injector?.get(DestroyRef) ?? inject(DestroyRef)
: null;

const equal = makeToSignalEquals(options?.equals);
const equal = makeToSignalEqual(options?.equal);

// Note: T is the Observable value type, and U is the initial value type. They don't have to be
// the same - the returned signal gives values of type `T`.
Expand Down Expand Up @@ -213,7 +213,7 @@ export function toSignal<T, U = undefined>(
});
}

function makeToSignalEquals<T>(
function makeToSignalEqual<T>(
userEquality: ValueEqualityFn<T> = Object.is,
): ValueEqualityFn<State<T>> {
return (a, b) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/core/rxjs-interop/test/to_signal_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ describe('toSignal()', () => {
const counter$ = new Subject<{value: number}>();
const counter = toSignal(counter$, {
initialValue: {value: 0},
equals: (a, b) => a.value === b.value,
equal: (a, b) => a.value === b.value,
});

let updates = 0;
Expand Down

0 comments on commit 5dcdbfc

Please sign in to comment.