Definitely some valid feedback Olivier. I'm working on this solo at the moment, but I can imagine it could potentially be confusing to work on for someone else.
Although, this pattern isn't necessarily something unique to JavaScript (or Typescript in this scenario), this treatment of functions as first class entities is one of the principles of functional programming in general.
For some more information, this sentence refers to a function I wrote, which is meant to write data to Firestore for a social media profile. In a function called writeSocialProfile, which accepts a function socialApiRequestFunction as a parameter.
This enables me to run different functions depending on the social media platform I'm looking at.
Essentially it just says "run getYoutubeProfile if socialName is youtube", and repeat that for each social media in a switch statement.
It definitely might not be as clean to read for new devs to the project, but it has a few benefits that IMO make it worthwhile.
It sped up my workflow of adding new social media platforms to the app, as my workflow could simply be:
- Write a new function
xyz to get a user's profile from a new social media platform abc.
- Write integration tests in Jest for this new isolated function (Jest was probably not ideal for this)
- Once the tests pass, add a case in the existing switch statement, for this new function
xyz to be returned when the value of socialName is abc
Definitely agree it might not be pretty to look at for people new to the codebase, but it made the flow a lot easier for me, with some added benefits of easy testing.