Skip to content

Commit

Permalink
Merge pull request #1726 from reduxjs/pr/remove-typeof
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson authored Aug 14, 2022
2 parents dc673a3 + 3bd595b commit 88692ae
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
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,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 @@ -263,7 +263,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ import type { BaseQueryFn } from '../baseQueryTypes'
// 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
Original file line number Diff line number Diff line change
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 88692ae

Please sign in to comment.