You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When working with large data sets, I have found integrity and visibility to be a problem. It is very easy to make a mistake where an incorrect number is used. This is made more confusing by the fact there are numeric indexes as strings and it would be an easy mistake to zero-index the reference.
Since the project is already in Typescript, I'd like to propose that the data format switch from a JSON file to exported constants with interfaces and enums.
This has a few benefits:
Type safe (interfaces and enums)
Data integrity (data must be well defined, duplicates, typos etc are caught by linters and at compile time.
Higher visibility of data
Massively reduces refactoring workload and merge conflicts
export enum Speaker {
'Example Person' = 'Example Person' , // string enum to make display easier.
...
}
export enum Category {
React
}
export enum Conference {
'Frontend Love Amsterdam 2018'
}
export interface IConferenceTalk {
speakers: Speaker[],
main_title: string
alternative_titles: string[],
categories: Category[],
video_url: string,
video_upload_date: Date,
conferences: Conference[]
}
// Visibility of the relationships here is much improved
export const CONFERENCE_TALKS: {[number]: IConferenceTalk} = {
"180": {
"speakers": [Speaker.'Example Person'],
"main_title": "Lightning launch - TakeShape",
"alternative_titles": [],
"categories": [Category.React],
"video_url": "https://youtu.be/ov9nZ2uBr2A",
"video_upload_date": new Date('2019-10-17'),
"conferences": [Conference.'Frontend Love Amsterdam 2018']
},
}
This would also make logic simpler in the React components that do the rendering, as they could just refer to myEnum[value] to get values.
Potentially JSON could still also be output at compile time or used as an input format to a parser than then validates the input, the downside to that option is it would still be easy to use an incorrect index.
If indexes were dropped from categories, speakers and conferences (possibly preserve them on conference talks), this would also massively reduce the number of merge conflicts and refactor work when there becomes a "race condition" on PRs using the same indexes.
I'd be interested in your thoughts
The text was updated successfully, but these errors were encountered:
When working with large data sets, I have found integrity and visibility to be a problem. It is very easy to make a mistake where an incorrect number is used. This is made more confusing by the fact there are numeric indexes as strings and it would be an easy mistake to zero-index the reference.
Since the project is already in Typescript, I'd like to propose that the data format switch from a JSON file to exported constants with interfaces and enums.
This has a few benefits:
Take for example:
clients/data/talks.json
Now becomes
clients/data/talks.ts
This would also make logic simpler in the React components that do the rendering, as they could just refer to
myEnum[value]
to get values.Potentially JSON could still also be output at compile time or used as an input format to a parser than then validates the input, the downside to that option is it would still be easy to use an incorrect index.
If indexes were dropped from categories, speakers and conferences (possibly preserve them on conference talks), this would also massively reduce the number of merge conflicts and refactor work when there becomes a "race condition" on PRs using the same indexes.
I'd be interested in your thoughts
The text was updated successfully, but these errors were encountered: