Code Monkey home page Code Monkey logo

Comments (9)

7nik avatar 7nik commented on July 18, 2024

Can you elaborate on what exactly you are doing or provide a REPL?

Also, the list of $effects dependencies is determined dynamically at runtime — $effect "listens" only for the signals it had read during the previous run.

from svelte.

Conduitry avatar Conduitry commented on July 18, 2024

We do need a concrete reproduction for this.

If your question is whether the $effect() block in a component should run when that component isn't even rendered, the answer to that is no. If that isn't the question, we need a repro.

from svelte.

henrikvilhelmberglund avatar henrikvilhelmberglund commented on July 18, 2024

You can hide it using CSS instead which will keep effects active but it will also keep state so you may need to handle that: REPL

If this isn't what you want post a REPL.

from svelte.

Tagman avatar Tagman commented on July 18, 2024

We do need a concrete reproduction for this.

If your question is whether the $effect() block in a component should run when that component isn't even rendered, the answer to that is no. If that isn't the question, we need a repro.

Yes, that was basically the question. I assume a {#if false} is not rendering the components inside.

I think I will have to find another way to the rest of my components about the changes.

You can hide it using CSS instead which will keep effects active but it will also keep state so you may need to handle that: REPL

If this isn't what you want post a REPL.

I was thinking along the same lines. But sadly this decreases my performance quite a lot, as I have numerous updates.

from svelte.

Tagman avatar Tagman commented on July 18, 2024

I created a simple REPL to hopefully clear up what I mean.
REPL

When the child is not hidden, it logs into the console that the counter was changed.
If the child is hidden, the effect is not triggered.

Is there any way I can work around this without "display: none"?

from svelte.

dummdidumm avatar dummdidumm commented on July 18, 2024

No - the if block destroys the component, and therefore anything within it. You could use display: none, or you could move the $effect out somewhere else if it's not tied to the component (which it sounds it isn't, if it should run when the component is not visible).
Closing as this is nothing we're going to change in Svelte.

from svelte.

Tagman avatar Tagman commented on July 18, 2024

I updated my REPL . The child now gets passed an array. I added an effect in the App.svelte which references this arr. But this upper most effect is not triggered, even though I added elements to the array. Is there a way to get this effect triggered when an element inside an array is modified?

I understand that the {#if} mechanism isnt going to be changed. I just wanted to know if there is somehow to make this situation work.

from svelte.

henrikvilhelmberglund avatar henrikvilhelmberglund commented on July 18, 2024

You could use .length as in the child for checking if the length changes. For modifications in the array itself I'm not too sure, I tried .flat() which seems to work but maybe there's something better. REPL

from svelte.

Tagman avatar Tagman commented on July 18, 2024

Length would not work in every case, as I typically update an object inside the array. And I would like to have the effect flash then as well.

flat() seems to work, but my next problem lies with the usage if reactive maps. I tried an ugly version with:

        const subservices: Service[] = Array.from(service.subServices.values());
        subservices.flat(Infinity);

But this didn't trigger updates.

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.