streamich/set-harmonic-interval

Feature Request: Allow consumer to control bucket ids

开放

#10 创建于 2020年6月1日

 (4 条评论) (1 个反应) (0 位负责人)TypeScript (1 个派生)github user discovery
good first issuehelp wanted

仓库指标

星标
 (12 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

All timers are grouped into "buckets" that are identified by the ms parameter. Using the ms parameter as a bucket identifier can have undesired consequences.

My suggestion: add an extra id parameter and use it as bucket identifier instead of ms parameter. Furthermore, I think this parameter should be required (it should not default to the value of ms). Which would be a non-backwards-compatible change.


Since, as I understand, set-harmonic-interval was developed to be used by react-use, let me use react-use as an example.

Suppose you want to have 2 sets of components - numerous instances of <X/> and numerous instances of <Y/> - and:

  • you want both <X/> and <Y/> to update after the same interval (same ms parameter value)
  • but you don't necessarily want instances of X to update when instances of Y update

This is impossible with the current implementation, because buckets are created per ms parameter.

Hopefully the above explanation is sufficient but consider this example for completeness: https://codesandbox.io/s/tender-kepler-9r1j1?file=/src/App.js The stoplights will harmonically change the light every 5 seconds. The triggers will harmonically flash every 5 seconds as well. But triggers will not start flashing until you press any of them. And if it just so happens, that you push the trigger 100ms before the stoplights are about to change, the trigger indicators will be on only for that 100ms, while I'd expect them to be on for the first 5 seconds after triggering.

贡献者指南