terrierscript
9/28/2018 - 1:15 PM

redux-observableで作ったintervalのobservableをHot Module Replacementで止まるようにする ref: https://qiita.com/terrierscript/items/f888a7b1b3021de24551

redux-observableで作ったintervalのobservableをHot Module Replacementで止まるようにする ref: https://qiita.com/terrierscript/items/f888a7b1b3021de24551

import { combineEpics } from "redux-observable"
import { interval, Subject } from "rxjs"
import { map, takeUntil } from "rxjs/operators"

const disposer = new Subject()

export const timerEpic = () => {
  return interval(1000).pipe(
    takeUntil(disposer), // disposerが動くまでtimerを動かす
    map((time) => ({
      type: "TIMER",
      value: time
    }))
  )
}

if (module.hot) {
  module.hot.dispose((data) => {
    disposer.next()
  })
}