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

Add watched and unwatched #634

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Add watched and unwatched #634

wants to merge 7 commits into from

Conversation

JoviDeCroock
Copy link
Member

@JoviDeCroock JoviDeCroock commented Dec 27, 2024

Resolves #351
Resolves #428

This adds a second argument to signal which are the options, currently this adds two properties, watched and unwatched. These will most likely serve third party libraries a lot more than first party consumers.

  • watched will trigger when the first subscriber subscribes to a signal
  • unwatched will trigger when the last subscriber unsubscribes from a signal

The second parameter can in the future be used for other RFC's in our pipeline like the equality function. The addition of this parameter is in line with the TC39 proposal for browser-native signals https://github.com/tc39/proposal-signals

I opted not to add this to computed for the time being as the signal itself is the atom while computed is more of a derived value. Not sure if a utility like this would be useful there. In the TC39 proposal they also add this to computed, so might as well for parity.

Note that calling the watcher on the subscribe is slightly distinct from how we normally treat signals, i.e. we calculate the computed when its value is accessed for the first time.

Copy link

changeset-bot bot commented Dec 27, 2024

🦋 Changeset detected

Latest commit: ee34c3c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@preact/signals-core Minor
@preact/signals Minor
@preact/signals-react Minor

Not sure what this means? Click here to learn what changesets are.

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

Copy link

netlify bot commented Dec 27, 2024

Deploy Preview for preact-signals-demo ready!

Name Link
🔨 Latest commit ee34c3c
🔍 Latest deploy log https://app.netlify.com/sites/preact-signals-demo/deploys/676ec90ce41dee0008453837
😎 Deploy Preview https://deploy-preview-634--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.

Copy link
Contributor

github-actions bot commented Dec 27, 2024

Size Change: +197 B (+0.24%)

Total Size: 83.5 kB

Filename Size Change
docs/dist/assets/bench.********.js 1.59 kB +3 B (+0.19%)
docs/dist/assets/index.********.js 838 B +2 B (+0.24%)
docs/dist/assets/signals-core.module.********.js 1.47 kB +54 B (+3.82%)
docs/dist/basic-********.js 245 B +2 B (+0.82%)
docs/dist/demos-********.js 3.45 kB +3 B (+0.09%)
docs/dist/nesting-********.js 1.13 kB -2 B (-0.18%)
docs/dist/react-********.js 241 B -1 B (-0.41%)
packages/core/dist/signals-core.js 1.51 kB +61 B (+4.22%)
packages/core/dist/signals-core.mjs 1.54 kB +63 B (+4.27%)
packages/preact/dist/signals.js 1.47 kB +4 B (+0.27%)
packages/preact/dist/signals.mjs 1.44 kB +8 B (+0.56%)
ℹ️ View Unchanged
Filename Size
docs/dist/assets/client.********.js 46.4 kB
docs/dist/assets/jsxRuntime.module.********.js 284 B
docs/dist/assets/preact.module.********.js 4.03 kB
docs/dist/assets/signals.module.********.js 2.16 kB
docs/dist/assets/style.********.js 21 B
docs/dist/assets/style.********.css 1.24 kB
packages/react-transform/dist/signals-*********.js 4.93 kB
packages/react-transform/dist/signals-transform.mjs 4.16 kB
packages/react-transform/dist/signals-transform.umd.js 5.04 kB
packages/react/dist/signals.js 188 B
packages/react/dist/signals.mjs 150 B

compressed-size-action

@JoviDeCroock JoviDeCroock force-pushed the watched branch 2 times, most recently from 53dcfe1 to 180a2e0 Compare December 27, 2024 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant