-
-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor selectSlice, distinctUntilSomeChanged, keyCompareMap (#159)
* refactor(state): refactored selectSlice, distinctUntilSomeChanged and keyCompareMap signatures * fix(state): KeyCompareMap adoption * docs(state): fixed jsDocs after refactor Co-authored-by: Michael Hladky <michael@hladky.at>
- Loading branch information
Showing
9 changed files
with
478 additions
and
515 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
# CompareFn | ||
|
||
The function which is used by `distinctUntilSomeChanged` and `selectSlice` to determine if changes are distinct or | ||
not. | ||
The function which is used by `KeyCompareMap` to determine if changes are distinct or not. | ||
Should return true if values are equal. | ||
|
||
## Signature | ||
|
||
```TypeScript | ||
type CompareFn<T> = (oldVal: T, newVal: T) => boolean | ||
type CompareFn<T> = ( | ||
oldVal: T | null | undefined, | ||
newVal: T | null | undefined | ||
) => boolean | ||
``` | ||
# KeyCompareMap | ||
The `KeyCompareMap` is used to configure custom comparison for defined keys. You can set the `CompareFn` to | ||
`undefined` in order to utilize the default equality check. | ||
The `KeyCompareMap` is used to configure custom comparison for defined keys. | ||
_Example_ | ||
```TypeScript | ||
const keyCompareMap = { | ||
myKey: (o, n) => customCompare(o, n), | ||
myOtherKey: undefined | ||
myKey: (o, n) => customCompare(o, n) | ||
}; | ||
const o$ = of({ | ||
myKey: 5, | ||
myOtherKey: 'bar' | ||
}).pipe(distinctUntilSomeChanged(keyCompareMap)); | ||
}).pipe(distinctUntilSomeChanged(['myKey', 'myOtherKey'], keyCompareMap)); | ||
|
||
//or | ||
|
||
const o$ = of({ | ||
myKey: 5, | ||
myOtherKey: 'bar' | ||
}).pipe(selectSlice(keyCompareMap)); | ||
}).pipe(selectSlice(['myKey', 'myOtherKey'], keyCompareMap)); | ||
``` | ||
|
||
## Signature | ||
|
||
```TypeScript | ||
type KeyCompareMap<T extends object> = { | ||
[K in keyof T]?: CompareFn<T[K]>; | ||
[K in keyof Partial<T>]: CompareFn<T[K]>; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.