Code Monkey home page Code Monkey logo

Comments (7)

brunnerh avatar brunnerh commented on June 19, 2024

This is intentional, tracking of dependencies does not work as maybe expected with async code.
(Anything after the first await will not be tracked.)

Duplicate of:

from svelte.

Dudek-AMS avatar Dudek-AMS commented on June 19, 2024

This seems also be the case when I use then semantic?

    let error : any = $state(null);

  $effect(() => {
        fetch(location.href, {
            method: 'POST',
            headers: {
                'content-type': 'application/json'
            },
            body: JSON.stringify({action: 'validatemail', email})
        }).then(res => res.json()).then(data => {
            error = data;
        });
    });

    $effect(() => {
        console.log(error);
    })

the console.log(error) isnt triggered

from svelte.

brunnerh avatar brunnerh commented on June 19, 2024

True, but there isn't anything Svelte can do about this.
Anything outside the range of types is a documentation issue.

from svelte.

brunnerh avatar brunnerh commented on June 19, 2024

Assignment should still trigger reactivity.
Only dependencies are not tracked in async code.

Can you create a standalone reproduction in the REPL?

from svelte.

Dudek-AMS avatar Dudek-AMS commented on June 19, 2024

NVM - its working - my mistake

so to have something async and make it reactive i have to inline the async function and do some magic with my dependencies manually?

    $effect(() => {
        dep1 && dep 2 && dep3;
        (async () => {
            //do magic here
        })();
    });

would it make sense to overload the functions to manually add additional dependencies to the $effect function?

$effect(myFn, [dep1, dep2, dep3]);

from svelte.

brunnerh avatar brunnerh commented on June 19, 2024

Evaluating the dependencies beforehand would be a good approach, though you should not use && since that will potentially skip latter dependencies. You can use dep1, dep2, dep3; instead.

Regarding the argument for listing dependencies, there is an existing issue:

from svelte.

Dudek-AMS avatar Dudek-AMS commented on June 19, 2024

Okay thanks for your feedback - im closing this issue on this point.

from svelte.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.