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

Reactivity doesn't work? #166

Closed
taw opened this issue Aug 16, 2020 · 8 comments · Fixed by #167
Closed

Reactivity doesn't work? #166

taw opened this issue Aug 16, 2020 · 8 comments · Fixed by #167

Comments

@taw
Copy link

taw commented Aug 16, 2020

So I've been trying to code a tiny app just to figure out how this works. I'm running it with tns preview and Android preview app.

The part that breaks is that it's supposed to display one icon or the other:

      {#if alive}
        <span class="fas alive" text="&#xf004;" />
      {:else}
        <span class="fas dead" text="&#xf54c;" />
      {/if}

Instead what I see is this when I get life to positive / negative is this:

2020-08-16 02 51 46

I tried a bunch of variants of this code (life >= 0, some extra reactive variable, with and without else block etc.) and result is always the same - the element that's supposed to be removed isn't removed.

I'm pretty sure it would work in regular Svelte.

So I think that's a bug in Svelte Native?

@halfnelson
Copy link
Owner

halfnelson commented Aug 16, 2020 via email

@taw
Copy link
Author

taw commented Aug 16, 2020

Is there any documentation of what works and what doesn't?

@halfnelson
Copy link
Owner

halfnelson commented Aug 16, 2020 via email

@taw
Copy link
Author

taw commented Aug 19, 2020

Here's something closer to minimum test case. This one does CATDOGCATDOGCATDOG...

<script>
  let cat = true;
</script>

<page>
	<stackLayout>
		<button on:tap={() => cat=true}>CAT</button>
		<button on:tap={() => cat=false}>DOG</button>
		<label>
			<formattedString>
				{#if cat}
					<span text="CAT" />
				{:else}
					<span text="DOG" />
				{/if}
			</formattedString>
		</label>
	</stackLayout>
</page>

I guess the whole formattedString would need to get nuked and regenerated on every update inside it?

@taw
Copy link
Author

taw commented Aug 19, 2020

Here's another one. This one doesn't update at all, stays as CAT regardless of component state:

<script>
  let cat = true;
</script>

<page>
  <stackLayout>
    <button on:tap={() => cat=true}>CAT</button>
    <button on:tap={() => cat=false}>DOG</button>
    <label>
      {#if cat}
        <formattedString>
          <span text="CAT" />
        </formattedString>
      {:else}
        <formattedString>
          <span text="DOG" />
        </formattedString>
      {/if}
    </label>
  </stackLayout>
</page>

@taw
Copy link
Author

taw commented Aug 19, 2020

Finally this one works:

<script>
  let cat = true;
</script>

<page>
  <stackLayout>
    <button on:tap={() => cat=true}>CAT</button>
    <button on:tap={() => cat=false}>DOG</button>
    {#if cat}
      <label>
        <formattedString>
          <span text="CAT" />
        </formattedString>
      </label>
    {:else}
      <label>
        <formattedString>
          <span text="DOG" />
        </formattedString>
      </label>
    {/if}
  </stackLayout>
</page>

It's still 2 components not updating their contents properly, failing in different ways (label just not updating; formattedString adding only).

@halfnelson
Copy link
Owner

halfnelson commented Aug 19, 2020 via email

@halfnelson
Copy link
Owner

Deployed in 0.8.5.
Thanks for the bug report and repro, this fix will help other components too 👍

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 a pull request may close this issue.

2 participants