Anger Management at Work

The emotion of anger has gotten a bad rap it does not deserve. We could not survive without anger. It is the power emotion, a signal that our interests are not being addressed and we want that…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Manage AJAX calls the RIGHT way!

Every time I get to the part of connecting my client to a server, I try to group my ajax calls in one place to keep it manageable,

Also to adapt fast, in a fast changing developing environment, lately I use a config file to create a flexible environment.

My solution look like that:

After using this method couple of times I decided to create an npm module to help me in my next project.

keep in mind that npm package still has to be written in es5.

This is how my package look like.

Now let’s try to break it down.

In order to provide flexibility between node and browser environment, checking for axios (HTTP library) in both options.

After configuring the variable in our function, im creating the function according the actions in the config file (like “get” above),

All the functions is actually the same, there is 2 factors that changes:

Pretty simple code, but acting this way will help you create client server bridge that you can maintain easily, for example try to think what happens if you pull the config from the server itself.

Add a comment

Related posts:

What Will The Future Of Nanotechnology Look Like In 5 Years?

The Center for Nanotechnology in Society has found that people respond differently to nanotechnology depending on the application. Public commentators are more favorable to the use of nanotechnology…

5 Warning Signs Your Morning Routine Needs a Total Make Over

Here are five warning signs your mourning routine needs a total make-over. Discover what they are and why you should look for these red flags.

Statistics for Machine learning data analysis.

Statistics are very important in data analysis for machine learning. They are the first contact to know about our data. we can ask questions from basic to advanced concepts. In this article, I’m…