preactjs / signals

Manage state with style in every framework
https://preactjs.com/blog/introducing-signals/
MIT License
3.62k stars 88 forks source link

refactor: inline Signal.prototype.subscribe implementation #527

Closed jviide closed 3 months ago

jviide commented 3 months ago

This pull request is a continuation for #523, where the Signal.prototype.subscribe method was implemented using the untracked() function, saving some bytes.

Inlining the untracked() call saves bytes for most output formats and solves the tree-shaking downside mentioned in #523.

Before:
       1481 B: signals-core.js.gz
       1350 B: signals-core.js.br
       1494 B: signals-core.mjs.gz
       1363 B: signals-core.mjs.br
       1488 B: signals-core.module.js.gz
       1352 B: signals-core.module.js.br
       1557 B: signals-core.min.js.gz
       1414 B: signals-core.min.js.br

After:
       1474 B: signals-core.js.gz
       1333 B: signals-core.js.br
       1497 B: signals-core.mjs.gz
       1364 B: signals-core.mjs.br
       1486 B: signals-core.module.js.gz
       1353 B: signals-core.module.js.br
       1550 B: signals-core.min.js.gz
       1412 B: signals-core.min.js.br

A new test case is included for checking that the subscription callback will run when the signal's original value changes after the subscription has been created.

changeset-bot[bot] commented 3 months ago

⚠️ No Changeset found

Latest commit: 9444f7955a44950781a4d0853680dba29d450989

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

netlify[bot] commented 3 months ago

Deploy Preview for preact-signals-demo ready!

Name Link
Latest commit 9444f7955a44950781a4d0853680dba29d450989
Latest deploy log https://app.netlify.com/sites/preact-signals-demo/deploys/65f279bf1d9b1c00081b48f8
Deploy Preview https://deploy-preview-527--preact-signals-demo.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 configuration.