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

Added untracked function #380

Merged
merged 12 commits into from
Jul 26, 2023
Merged

Added untracked function #380

merged 12 commits into from
Jul 26, 2023

Conversation

XantreDev
Copy link
Contributor

@XantreDev XantreDev commented Jul 5, 2023

Resolves #378

As mentioned in the proposal this allows us to write effects that essentially aren't re-executed by the signals that get accessed in the function body of untracked.

Allowing functionality like

function reaction(sender, listener) {
  effect(() => {
    const value = sender();
    untracked(() => {
      listener(value);
    });
  }
}

@changeset-bot
Copy link

changeset-bot bot commented Jul 5, 2023

🦋 Changeset detected

Latest commit: 5c72e9a

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

This PR includes changesets to release 1 package
Name Type
@preact/signals-core 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

@netlify
Copy link

netlify bot commented Jul 5, 2023

Deploy Preview for preact-signals-demo ready!

Name Link
🔨 Latest commit 5c72e9a
🔍 Latest deploy log https://app.netlify.com/sites/preact-signals-demo/deploys/64c024072037800008e67821
😎 Deploy Preview https://deploy-preview-380--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.

@XantreDev XantreDev changed the title Added untrack function Added untracked function Jul 5, 2023
@XantreDev XantreDev changed the title Added untracked function Added untracked function Jul 5, 2023
@XantreDev
Copy link
Contributor Author

XantreDev commented Jul 6, 2023

@andrewiggins I will be appreciate if you give feedback)

@andrewiggins
Copy link
Member

Hey! One question that comes to mind for me is what use case does this help that use const value = signal.peek() doesn't work for?

@XantreDev
Copy link
Contributor Author

XantreDev commented Jul 6, 2023

Some reasons is specified in proposal linked to the PR.
But shortly: its useful for creating utils that works with callbacks. Most of reactive runtime provides untracked, so it's common pattern, that allows to manipulate reactivity not on sender side, but in consumer side.
Yes, I can emulate untracked with computed, but it has too much overhead IMHO.

const untracked = (callback) => computed(callback).peek()

And I am not sure that I can modify values in computed, it feels weird

@andrewiggins
Copy link
Member

Oh whoops! I missed the linked proposal. Lemme take a look and mull it over with the team

@XantreDev
Copy link
Contributor Author

I think this thing are essential for writing Store-like primitives and dealing with it without tricks

@XantreDev
Copy link
Contributor Author

@andrewiggins when you will return with feedback?

@andrewiggins
Copy link
Member

I have some vacation coming up so will be away for a week or two. Though if other core team members have thoughts, no need to block on me

@XantreDev
Copy link
Contributor Author

@JoviDeCroock what do you think about untracked?

@JoviDeCroock
Copy link
Member

This looks good to me, tests seem to be failing and needs a changeset

@XantreDev
Copy link
Contributor Author

This looks good to me, tests seem to be failing and needs a changeset

Fixed

.changeset/dirty-geese-learn.md Outdated Show resolved Hide resolved
@JoviDeCroock JoviDeCroock merged commit 256a331 into preactjs:main Jul 26, 2023
5 checks passed
@github-actions github-actions bot mentioned this pull request Jul 26, 2023
@betula
Copy link

betula commented Jul 26, 2023

Thanks a lot👍

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.

Proposal: untracked api function
4 participants