glideapps / glideapps/glide-data-grid
[Improvement] useAsyncDataSource cache invalidation
- Dominant language
- TypeScript
- Stars
- 5.3k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
It would be nice to be able to invalidate rows cached by the `useAsyncDataSource` hook.
My API suggestion would be to return an additional object in this hook, say a "cache" object, which encapsulates the internal cache and allows some control from the outside.
Perhaps this could be the type def for this cache:
```typescript
interface AsyncDataSourceCache {
/**
* Gets the cached object (if there is any) for the given row.
*/
get: (row: number) => TData | undefined
/**
* Invalidate the given cached rows, when no rows are specified, the entire cache is invalidated.
*/
invalidate(rows?: number[]) => void
}
````
This allows easy access to cached row objects, which can come in handy when processing the grid events. It also allows invalidating any rows (say, by controlling their timestamp or whatever logic the client needs).
Currently, I have a component that needs this type of functionality and I had to resort to changing the component's key just to "clear" the internal state of the hook.
Contributor guide
Assessment
This issue has not been assessed yet.