DEV Community

Discussion on: 3 reasons you should try Svelte

Collapse
 
jonrandy profile image
Jon Randy 🎖️

Or you could try RiotJS which appears to have heavily influenced Svelte, and is a lot more mature - it's on version 4 (version 5 is in alpha)and has been around since 2013. A similar timer component would be defined as follows:

<timer>
  <p>Seconds Elapsed: { state.time }</p>

  <script>
    export default {
      tick() {
        this.update({ time: ++this.state.time })
      },
      onBeforeMount(props) {
        // create the component initial state
        this.state = {
          time: props.start
        }

        this.timer = setInterval(this.tick, 1000)
      },
      onUnmounted() {
        clearInterval(this.timer)
      }
    }
  </script>
</timer>