3.6.0 • Published 3 months ago

@reatom/timer v3.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Timer model to manage some countdown. Useful for classic pomodoro or any time-progress states, like notifications.

import { reatomTimer } from '@reatom/timer'

// all options are not required, here are the defaults
const pomodoroAtom = reatomTimer({
  name: 'pomodoroAtom',
  interval: 1000, // `1000`ms - tick each second. Than lower, then more precise
  delayMultiplier: 1000, // `1000`ms allow to pass seconds to startTimer. Use `1` to pass ms
  progressPrecision: 2, // progress will be rounded to 2 digits after dot
  resetProgress: true, // progress will be reset to 0 on end of timer
})

The timer itself contains the ms remaining to the end of the timer (0 before start). Here is the list of available states and methods:

  • progressAtom (Atom<number>) - from 0 to 1, (delay - remains) / delay
  • intervalAtom (AtomMut<number>) - interval of ticks in ms
  • startTimer (Action<[delay: number, passed?: number], Promise<void>>) - start timer with the delay and optional start point
  • stopTimer (Action<[], void>) - stop timer manually
  • pauseAtom (AtomMut<boolean>) - allow to pause timer
  • pause (Action<[], boolean>) - switch pause state
  • endTimer (Action<[], void>) - track end of timer. Do not call manually!

Examples

3.6.0

3 months ago

3.5.6

6 months ago

3.5.5

10 months ago

3.5.3

1 year ago

3.5.2

1 year ago

3.4.0

1 year ago

3.3.0

1 year ago

3.2.0

1 year ago

3.5.1

1 year ago

3.4.2

1 year ago

3.4.1

1 year ago

3.1.1

1 year ago

3.1.0

2 years ago