How to manage large number of similar REST calls in JS/TS?

import APIModule from ‘whatever/path/APIModule’
// …
const apiModule = APIModule.getInstance()

What I did was instantiate APIModule in file A directly and export it as a constant like this. Then import that constant in file B and C.

const apiModule = Object.freeze(APIModule.getInstance());
export default apiModule;

I figured that way I don’t need to write APIModule.getInstance in every file where I use it.

As to TS in general … at the risk of getting into opinion territory … I think TS is the wave of the future. It has been shooting up in popularity and “fixes” some of the “problems” with JS. I think any smart JS developer needs to learn TS.

I enjoy TS and find it satisfying to learn. However, I have heard some hardcore JS old-timers saying it is terrible for JS. Those same people are also not in favour of inheritance in JS, but I like it as I find it very intuitive to write, read and understand and gives me good control over my code. Although, I am sure you can do the same thing without it. You mentioned e.g. # which I read about recently somewhere.

Sure, I’ve seen patterns like that. It seems a little odd to me, some modules exporting class definitions and some exporting instances, but whatever.

However, I have heard some hardcore JS old-timers saying it is terrible for JS.

Pick any subject in coding and people will have strong opinions. Some people will purposely have strong attention to attract attention, sometimes for financial gain.

I just look at the steady growth of TS. There is plenty of data to show that TS keeps growing, like here. You will also find people complaining about it. You can also find people that don’t like ice cream.

I think that learning TS has improved how I code. When I write vanilla JS, I now write it better. I would say that unit testing did the same thing - it made me a better coder. #ymmv

You will also find people complaining about it. You can also find people that don’t like ice cream.

:grinning:

I would say that unit testing did the same thing - it made me a better coder. #ymmv

That is on my list to learn!

Sure, I’ve seen patterns like that. It seems a little odd to me, some modules exporting class definitions and some exporting instances, but whatever.

I might reconsider.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.