Skip to content

Rewrite Subscription as a closure factory for byte shaving #1755

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

Merged
merged 4 commits into from
Jul 6, 2021

Conversation

markerikson
Copy link
Contributor

This PR:

  • Rewrites the Subscription class to be a closure factory instead, which should shrink minified size by about 300 bytes
  • Switches bindActionCreators back to the simpler version we had when we copied it over to save a few more bytes

The Subscription class is one of the two biggest pieces when you import useSelector, the other being the useSelector hook itself. I noticed that when we converted Subscription to TS, we added some uses of the ?. optional chaining operator, but each of those gets compiled into several null/undefined checks.

I went to change the optional chaining back to simple if clauses instead, but then realized that if I switched this to be a closure factory, I could drop all the uses of this as a bonus.

We can apply the same changes over in the 7.2 line as well.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 6, 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 20a2394:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration

@github-actions
Copy link

github-actions bot commented Jul 6, 2021

Size Change: -755 B (3%)

Total Size: 19.4 kB

Filename Size Change
dist/react-redux.js 14.7 kB -457 B (3%)
dist/react-redux.min.js 4.75 kB -298 B (6%)

compressed-size-action

@netlify
Copy link

netlify bot commented Jul 6, 2021

✔️ Deploy Preview for react-redux-docs ready!

🔨 Explore the source changes: 20a2394

🔍 Inspect the deploy log: https://app.netlify.com/sites/react-redux-docs/deploys/60e3b1db633fd50007e0eeb7

😎 Browse the preview: https://deploy-preview-1755--react-redux-docs.netlify.app

@markerikson markerikson force-pushed the feature/subscription-size branch 2 times, most recently from aec28bf to dc2b380 Compare July 6, 2021 01:23
@markerikson markerikson force-pushed the feature/subscription-size branch from dc2b380 to 20a2394 Compare July 6, 2021 01:28
@markerikson markerikson merged commit fad30d6 into typescript-port Jul 6, 2021
@markerikson markerikson deleted the feature/subscription-size branch July 6, 2021 01:33
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.

1 participant