mandaputtra
mandaputtra

Reputation: 1070

how to trigger fromEvent() rxjs with button on click?

What i want?

Countdown when click play button

Code

I use vuejs and vuerx to do this. here my code

<script>
/* eslint-disable */
import { Observable, Subscription } from 'rxjs'

export default {
  data() {
    return {
      energy: 12
    }
  },
  domStreams: ["play$"],
  subscriptions() {
    const energy$ = Observable.interval(250)
    .fromEvent(play$, 'click')
    .startWith(this.energy)
    .scan(time => time - 1)
    .takeWhile(time => time > 0)
    return {
      energy$
    }
  }
}
</script>

my HTML

<template>
  <div>
    <button @click="play$">Play</button>
    <input type="text" v-model="energy">
    <br>
    <h1>{{ energy$ }}</h1>
  </div>
</template>

Error message :

https://pastebin.com/umEYDejs

Upvotes: 0

Views: 560

Answers (0)

Related Questions