nodegui / svelte-nodegui

Build performant, native and cross-platform desktop applications with native Svelte + powerful CSS-like styling.🚀
https://svelte.nodegui.org/
MIT License
2.84k stars 55 forks source link

Reactivity is not working #34

Closed repomaa closed 3 years ago

repomaa commented 3 years ago

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>
shirakaba commented 3 years ago

@repomaa Looking into it...

shirakaba commented 3 years ago

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