nodegui/svelte-nodegui

Reactivity is not working

repomaa opened this issue · 2 comments

Hi! I tried out svelte-nodegui but found that reactivity isn't working. See this example component:

<script type="ts">
  let lastClick: number | null = null;
  let times: number[] = [];

  function tap() {
    const timestamp = new Date().getTime();

    if (lastClick) {
      times = [...times, timestamp - lastClick];
    }

    lastClick = timestamp;

    if (times.length > 10) {
      times = times.slice(1);
    }
  }

  $: averageTimeBetweenClicks =
    times.reduce((acc, current) => acc + current, 0) / times.length;
  $: bpm = lastClick ? Math.round(60000 / averageTimeBetweenClicks) : "?";
</script>

<view>
  <button id="tap" on:clicked={tap}>Tap</button>
  <text>BPM: {bpm}</text>
</view>

<style>
  #tap {
    width: 100px;
    height: 100px;
  }
</style>

@repomaa Looking into it...

Fixed in v0.0.1-alpha.7! Huge thanks for catching this :)