Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove typeof undefined checks where not necessary 馃悆馃獟 #1726

Merged
merged 1 commit into from Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/toolkit/src/createReducer.ts
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
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 @@ -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
Comment on lines 59 to 64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be even shorter? It looks like there are many implementations that are just:

typeof document !== 'undefined' ? useLayoutEffect : useEffect

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I would normally say "those other implementations are probably wrong", but Andarist normally knows what he's doing.

I'm going to say leave this alone - it's there, we know it works.


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