Skip to content

Commit

Permalink
remove typeof undefined checks where not necessary 馃悆馃獟
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenz Weber committed Nov 12, 2021
1 parent b208e63 commit f1ed0e4
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/toolkit/src/createReducer.ts
Expand Up @@ -249,7 +249,7 @@ export function createReducer<S extends NotFunction<any>>(
const draft = previousState as Draft<S> // We can assume this is already a draft
const result = caseReducer(draft, action)

if (typeof result === 'undefined') {
if (result === undefined) {
return previousState
}

Expand All @@ -259,7 +259,7 @@ export function createReducer<S extends NotFunction<any>>(
// return the caseReducer func and not wrap it with produce.
const result = caseReducer(previousState as any, action)

if (typeof result === 'undefined') {
if (result === undefined) {
if (previousState === null) {
return previousState
}
Expand Down
7 changes: 1 addition & 6 deletions packages/toolkit/src/immutableStateInvariantMiddleware.ts
Expand Up @@ -67,12 +67,7 @@ function getSerialize(
* @public
*/
export function isImmutableDefault(value: unknown): boolean {
return (
typeof value !== 'object' ||
value === null ||
typeof value === 'undefined' ||
Object.isFrozen(value)
)
return typeof value !== 'object' || value == null || Object.isFrozen(value)
}

export function trackForMutations(
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/fetchBaseQuery.ts
Expand Up @@ -104,7 +104,7 @@ function stripUndefined(obj: any) {
}
const copy: Record<string, any> = { ...obj }
for (const [k, v] of Object.entries(copy)) {
if (typeof v === 'undefined') delete copy[k]
if (v === undefined) delete copy[k]
}
return copy
}
Expand Down
4 changes: 2 additions & 2 deletions packages/toolkit/src/query/react/buildHooks.ts
Expand Up @@ -55,8 +55,8 @@ import { useShallowStableValue } from './useShallowStableValue'
// Copy-pasted from React-Redux
export const useIsomorphicLayoutEffect =
typeof window !== 'undefined' &&
typeof window.document !== 'undefined' &&
typeof window.document.createElement !== 'undefined'
window.document &&
window.document.createElement
? useLayoutEffect
: useEffect

Expand Down
3 changes: 1 addition & 2 deletions packages/toolkit/src/serializableStateInvariantMiddleware.ts
Expand Up @@ -14,8 +14,7 @@ import { getTimeMeasureUtils } from './utils'
export function isPlain(val: any) {
const type = typeof val
return (
type === 'undefined' ||
val === null ||
val == null ||
type === 'string' ||
type === 'boolean' ||
type === 'number' ||
Expand Down

0 comments on commit f1ed0e4

Please sign in to comment.