Seerden / track

timekeeping
0 stars 0 forks source link

`byId` refactor #92

Closed Seerden closed 1 week ago

Seerden commented 1 week ago

Instead of creating a complicated TypeScript helper function that extracts the entries generally, e.g. like

const activities: ActivityWithIds[] = getEntries(activitiesData)
const tasks: TaskWithIds[] = getEntries(tasksData)

where the type of activitiesData is { activitiesById: Record<ID, ActivityWithIds> } and likewise for tasksData,

I've decided that it's much less mental overhead and also less implementation hassle to simply return things like

{ byId: tasksById } 

from the backend, that way the Data type we use is the only typing we need to do for this, and we never have to think about what properties to use, etc., and we can always expect that thing.byId will work for things that come from the backend as objects grouped by ID.

This closes #62 as obsolete.

I also added a DataById type to prevent having to rewrite Data<"byId", ById<ThingWithIds[]>> over and over.