preactjs / signals

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

refactor: use untracked to implement Signal.prototype.subscribe #523

Closed jviide closed 3 months ago

jviide commented 3 months ago

This pull request uses the untracked() function to simplify the implementation of the Signal.prototype.subscribe method. The functionality of the method stays the same.

Byte savings fall between 2 and 19 bytes, depending on the bundling output format:

Before this PR:
       1487 B: signals-core.js.gz
       1352 B: signals-core.js.br
       1513 B: signals-core.mjs.gz
       1378 B: signals-core.mjs.br
       1498 B: signals-core.module.js.gz
       1369 B: signals-core.module.js.br
       1561 B: signals-core.min.js.gz
       1421 B: signals-core.min.js.br

After this PR:
       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

The downside is that untracked can't get tree-shaken as easily. Fortunately, based on a quick test that only imported signal+computed+effect, the amount of removed code is enough that the end result seems to save bytes also in cases where untracked would have been tree-shaken before.

changeset-bot[bot] commented 3 months ago

⚠️ No Changeset found

Latest commit: 3e58027e0b8aaabc21c68a3e1c0017128c50b443

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 3e58027e0b8aaabc21c68a3e1c0017128c50b443
Latest deploy log https://app.netlify.com/sites/preact-signals-demo/deploys/65f22709c0ab690008c88d63
Deploy Preview https://deploy-preview-523--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.