Skip to content

Commit

Permalink
refactor(store): use Object.is as default equality check (#2245)
Browse files Browse the repository at this point in the history
In this commit, we default to using `Object.is` as the equality check function
(this function is also used by other frameworks). `Object.is` supports checking for `NaN`
values internally. We have also removed the reset function, as it was unused. If needed
in the future, it can be re-added.
  • Loading branch information
arturovt authored Nov 8, 2024
1 parent 82e1215 commit 583f543
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ $ npm install @ngxs/store@dev

- Fix(store): Prevent writing to state once action handler is unsubscribed [#2231](https://github.com/ngxs/store/pull/2231)
- Performance(store): Replace `instanceof Function` with `typeof` [#2247](https://github.com/ngxs/store/pull/2247)
- Refactor(store): Use `Object.is` as default equality check [#2245](https://github.com/ngxs/store/pull/2245)

### 18.1.4 2024-10-23

Expand Down
18 changes: 1 addition & 17 deletions packages/store/internals/src/memoize.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
const isNaN = Number.isNaN;
function defaultEqualityCheck(a: any, b: any) {
if (a === b) {
return true;
}

// Special case for `NaN` (NaN !== NaN).
// According to the IEEE 754 standard, `NaN` is not equal to any value,
// including itself.
if (isNaN(a) && isNaN(b)) {
return true;
}

return false;
}

function areArgumentsShallowlyEqual(
equalityCheck: (a: any, b: any) => boolean,
prev: IArguments | null,
Expand Down Expand Up @@ -43,7 +27,7 @@ function areArgumentsShallowlyEqual(
*/
export function ɵmemoize<T extends (...args: any[]) => any>(
func: T,
equalityCheck = defaultEqualityCheck
equalityCheck = Object.is
): T {
let lastArgs: IArguments | null = null;
let lastResult: any = null;
Expand Down

0 comments on commit 583f543

Please sign in to comment.