Debounce a state change with a sustain.
This is debounce with true|false passed to the callback.
In this example the value of scrolling will be true during the scroll event and for 250ms after.
import sustain from 'sustain';
let scrolling = false;
sustainScrolling = sustain(250, (state) => scrolling = state)
addEventListener('scroll', sustainScrolling)In this example the value of sustainScrolling.state will reflect whether scrolling is true or false
import { sustainState } from 'sustain';
sustainScrolling = sustain(250)
addEventListener('scroll', sustainScrolling)The value of sustainState.state can be given by the callback
sustainState(250, (sustained, prevState) =>
sustained ? { count: prevState.count + 1 } : { count: 0 ))