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’ll 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

Conversation

phryneas
Copy link
Member

@phryneas phryneas commented Nov 12, 2021

This is just a bit of yak shaving, but I noticed we are doing the typeof x === 'undefined' check in quite some places where we would not need to. I changed it to x === undefined (or x == null if there was an x === null check going on in parallel anyways).

I kept the behaviour for non-local variables like window, navigator, process and AbortController.

@github-actions
Copy link

size-limit report 📦

Path Size
1. entry point: @reduxjs/toolkit (cjs.production.min.js) 12.87 KB (-0.07% 🔽)
1. entry point: @reduxjs/toolkit (esm.js) 10.75 KB (-0.03% 🔽)
1. entry point: @reduxjs/toolkit/query (cjs.production.min.js) 22.5 KB (-0.03% 🔽)
1. entry point: @reduxjs/toolkit/query (esm.js) 18.85 KB (0%)
1. entry point: @reduxjs/toolkit/query/react (cjs.production.min.js) 24.63 KB (-0.04% 🔽)
1. entry point: @reduxjs/toolkit/query/react (esm.js) 21.38 KB (-0.01% 🔽)
2. entry point: @reduxjs/toolkit (without dependencies) (cjs.production.min.js) 5.69 KB (-0.09% 🔽)
2. entry point: @reduxjs/toolkit (without dependencies) (esm.js) 5.65 KB (-0.09% 🔽)
2. entry point: @reduxjs/toolkit/query (without dependencies) (cjs.production.min.js) 9.99 KB (0%)
2. entry point: @reduxjs/toolkit/query (without dependencies) (esm.js) 10.41 KB (0%)
2. entry point: @reduxjs/toolkit/query/react (without dependencies) (cjs.production.min.js) 2.65 KB (-0.08% 🔽)
2. entry point: @reduxjs/toolkit/query/react (without dependencies) (esm.js) 2.49 KB (-0.16% 🔽)
3. createSlice (esm.js) 5.03 KB (0%)
3. createEntityAdapter (esm.js) 6.28 KB (0%)
3. configureStore (esm.js) 5.62 KB (0%)
3. createApi (esm.js) 17.06 KB (0%)
3. createApi (react) (esm.js) 19.64 KB (-0.01% 🔽)
3. fetchBaseQuery (esm.js) 11.57 KB (0%)
3. setupListeners (esm.js) 10.39 KB (0%)
3. ApiProvider (esm.js) 18.48 KB (-0.02% 🔽)

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 12, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 3bd595b:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration
rsk-github-issues-example Configuration
@examples-query-react/basic Configuration
@examples-query-react/advanced Configuration
@examples-action-listener/counter Configuration

Copy link
Member

@msutkowski msutkowski left a comment

Choose a reason for hiding this comment

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

Overall looks good to me, just a quick question about the ismorphic layout effect check.

Comment on lines 56 to 64
export const useIsomorphicLayoutEffect =
typeof window !== 'undefined' &&
typeof window.document !== 'undefined' &&
typeof window.document.createElement !== 'undefined'
window.document &&
window.document.createElement
? useLayoutEffect
: useEffect
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.

Base automatically changed from v1.7.0-integration to master December 10, 2021 19:02
@phryneas phryneas added this to the 1.9 milestone Jul 3, 2022
@markerikson markerikson removed this from the 1.9 milestone Aug 14, 2022
@netlify
Copy link

netlify bot commented Aug 14, 2022

Deploy Preview for redux-starter-kit-docs ready!

Name Link
🔨 Latest commit 3bd595b
🔍 Latest deploy log https://app.netlify.com/sites/redux-starter-kit-docs/deploys/62f86c0d437f4500091d8588
😎 Deploy Preview https://deploy-preview-1726--redux-starter-kit-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@markerikson markerikson merged commit 88692ae into master Aug 14, 2022
@markerikson markerikson deleted the pr/remove-typeof branch August 14, 2022 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants