class {
  onCreate() {
    this.state = {
      running: false,
      elapsedTime: 0
    };

    this.intervalId = null;
  }

  onDestroy() {
    if (this.state.running) {
      clearInterval(this.intervalId);
    }
  }

  handleStartClick() {
    this.state.running = true;

    this.intervalId = setInterval(() => {
      this.state.elapsedTime += 0.1;
    }, 100);
  }

  handlePauseClick() {
    clearInterval(this.intervalId);

    this.state.running = false;
  }

  handleStopClick() {
    clearInterval(this.intervalId);

    this.state.running = false;
    this.state.elapsedTime = 0;
  }
}

style {
  .count {
    color:#70b;
    font-size:3em;
  }

  .example-button {
    font-size:1em;
    padding:0.5em;
  }
}

<div>
  <p>
    Elapsed time: ${state.elapsedTime.toFixed(1)}s
  </p>
  <button type="button" disabled=(state.running === true)
    on-click("handleStartClick")>
    Start
  </button>
  <button type="button" disabled=(state.running !== true)
    on-click("handlePauseClick")>
    Pause
  </button>
  <button type="button" disabled=(state.elapsedTime === 0 && state.running === false) on-click("handleStopClick")>
    Stop/Clear
  </button>
</div>
