Skip to content

Instantly share code, notes, and snippets.

@gaberogan
Created March 27, 2026 22:07
Show Gist options
  • Select an option

  • Save gaberogan/cb0d510f949184ab09d33bc8d8a716a9 to your computer and use it in GitHub Desktop.

Select an option

Save gaberogan/cb0d510f949184ab09d33bc8d8a716a9 to your computer and use it in GitHub Desktop.
Simplified gridRefresh.ts - targeted cell refresh without reverse index maps
// gridRefresh.ts - simplified
// Targeted cell refresh: when socket entities change, scan grid rows for matching keys
// and only refresh those rows. No reverse index maps needed.
import { getMasterGrid } from 'lib/agGrid'
import { throttle } from 'lodash'
const pendingEventIds = new Set<string>()
const pendingPlayerIds = new Set<string>()
const pendingStatTypeIds = new Set<string>()
const throttledResort = throttle(
() => {
const grid = getMasterGrid()
if (grid && !grid.isDestroyed()) grid.refreshClientSideRowModel('sort')
},
1000,
{ leading: false, trailing: true },
)
const flush = () => {
const grid = getMasterGrid()
if (!grid || grid.isDestroyed()) return
// snapshot and clear
const eIds = new Set(pendingEventIds)
const pIds = new Set(pendingPlayerIds)
const sIds = new Set(pendingStatTypeIds)
pendingEventIds.clear()
pendingPlayerIds.clear()
pendingStatTypeIds.clear()
// scan once, collect matches
const rowNodes = []
grid.forEachNode((node) => {
const d = node.data
if (!d) return
if (eIds.has(String(d.event_id)) ||
pIds.has(String(d.player_id)) ||
sIds.has(String(d.stat_type_id))) {
rowNodes.push(node)
}
})
if (!rowNodes.length) return
grid.refreshCells({ rowNodes })
throttledResort()
}
const scheduleFlush = throttle(flush, 500, { leading: true, trailing: true })
export const addPendingKeys = (keys) => {
keys.eventIds?.forEach((id) => pendingEventIds.add(String(id)))
keys.playerIds?.forEach((id) => pendingPlayerIds.add(String(id)))
keys.statTypeIds?.forEach((id) => pendingStatTypeIds.add(String(id)))
scheduleFlush()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment