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

optimize useContext call #2226

Merged
merged 1 commit into from
Jul 18, 2024

Conversation

mdynnl
Copy link
Contributor

@mdynnl mdynnl commented Jul 18, 2024

Summary

No benchmarks are ran as this should not need one. Feel free to do though 😂.

How did you test this change?

pnpm test

Copy link

changeset-bot bot commented Jul 18, 2024

⚠️ No Changeset found

Latest commit: 287acff

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coveralls
Copy link

Pull Request Test Coverage Report for Build 9997328613

Details

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 93.561%

Totals Coverage Status
Change from base Build 9751531446: 0.001%
Covered Lines: 4187
Relevant Lines: 4409

💛 - Coveralls

@ryansolid
Copy link
Member

ryansolid commented Jul 18, 2024

Nice that saves 8 bytes minified and is probably a tiny bit faster

@ryansolid ryansolid merged commit 2ae7d1d into solidjs:main Jul 18, 2024
1 check passed
@mdynnl mdynnl deleted the tiny-use-context-optimization branch July 19, 2024 05:30
return Owner && Owner.context && Owner.context[context.id] !== undefined
? Owner.context[context.id]
let value: undefined | T;
return Owner && Owner.context && (value = Owner.context[context.id]) !== undefined

Choose a reason for hiding this comment

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

how about

Owner?.context?.[context.id] ?? context.defaultValue

Copy link
Member

Choose a reason for hiding this comment

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

I've been avoiding optional chaining as we don't transform JS in the repo and some platforms down't support optional chaining. We've had issue trying to introduce it in the past.

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.

4 participants