this is a react context based npm package for batching calls to a function. it supports creating several trackers that can track state change by following individual data objects. the goal with the lib is to facilitate autosave and undo functionality, and for optimising client -> API requests with callbacks containing a batched data set.
npm install
yarn install
before anything doing else, you need to create a new batch tracker. you need to give it a name, a timeout (in ms) and a callback function.
since this lib is based on react context, you will be able to get access to all the initiated trackers globally in your app.
it makes sense to create a new tracker for each component or group of component whose state has some common goal. they might have a common state that needs to be CRUD:ed with a database with autosave functionality. or maybe it makes sense from a UX perspective to keep track of their combined history of states to implement something like an undo/redo functionality.
whenever an event occurs that should trigger the countdown for the callback function, you need it to register an action. it makes sense to have this happen on an onChange
type of event, as shown below.
the code above will produce a behaviour as shown in the gif below
tbc