-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
docs: clarify example on dynamic dependency tracking #13767
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
docs: clarify example on dynamic dependency tracking #13767
Conversation
|
21c7c85 to
01197d6
Compare
|
Maybe we could add a potential workaround, to further clarify the behaviour? Example: Escape Hatch: Forcing Effect Re-Runs on Every State ChangeIf you really need to ensure that the effect always runs when either let a = $state(false);
let b = $state(false);
$effect(() => {
// Explicitly reference `a` and `b` so this effect re-runs whenever they change
a;
b;
// This will run on every change to either `a` or `b`
console.log('running');
if (a || b) {
console.log('inside if block');
}
});This approach establishes direct dependencies on both
|
01197d6 to
36116fc
Compare
|
We could do something like that. Though, my original scope for this PR was to simply expound on the I'll wait on the Svelte team to chime in on how to best proceed here. |
|
Hello there! Just gonna bump this PR. I'd like to know if there are any concerns with the way I worded the clarification (and possibly improvements if necessary). Thanks again! |
|
preview: https://svelte-dev-git-preview-svelte-13767-svelte.vercel.app/ this is an automated message |
|
thank you! |
Description
This PR clarifies the explanation behind the short-circuiting
a || bexample used in the$effectguide. I personally felt like the original explanation was too short and too handwavy over the fascinating implications of dynamic dependency tracking. So, I expanded the explanation to cover both cases (i.e., whenaisfalseand whenaistrue).Before submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.Tests and linting
pnpm testand lint the project withpnpm lint