mhkeller / layercake

graphics framework for sveltejs
https://layercake.graphics
MIT License
1.41k stars 31 forks source link

Adds index to accessor functions #207

Closed mhkeller closed 5 months ago

mhkeller commented 5 months ago

Normally you're passing an array of objects but I've been thinking about alternate setups where maybe you want to keep your data as separate typed arrays for x and y. You'd have something like

const xVector = new Uint32Array(data.map(d => d[xKey]));
const yVector = new Uint8Array(data.map(d => d[yKey]));

and then...

...
x={(d, i) => xVector[i]}
y={(d, i) => yVector[i]}
data={someFakeDataHere}

This is kind of a weird setup but I could see it possibly being useful for high-performance cases. Either way, seems potentially helpful to have the index in the accessory anway...