mockit icon indicating copy to clipboard operation
mockit copied to clipboard

Removed unnecessary page reloads when operations like create, edit,…

Open stz184 opened this issue 4 years ago • 2 comments

Why

Currently, mockit starts a development server on production and expects webpack to reload the page every time when ./config/routes.json is modified. Yes, it works, but it is fundamentally wrong, it makes pointless the use of react and SPA principles, reveals configuration and code errors, it does not respect "homepage" property in package.json which makes the app impossible to be used inside a subdirectory. It is like making a coffee in a microwave oven - yes, it will probably brew, but it will not have the taste of the coffee prepared on an espresso machine.

How How I fixed it? Easily. First, the backend server is now extended with a new route called /routes that basically returns what we have in routes.json. This endpoint is called with fetch to retrieve the routes and settings instead of reading directly the file. As an added benefit, you can now deploy the backend server and the fronted app on completely different physical machines and the whole MockIt app will still work.

I have also used useCallback hook to avoid unnecessary component rerenderings.

There are some outstanding issues making the app works properly inside subfolder, but I will place yet another PR if this one is well accepted.

stz184 avatar Jan 05 '21 12:01 stz184

Codecov Report

Merging #90 (1d209eb) into master (e593e5d) will decrease coverage by 0.77%. The diff coverage is 84.84%.

@@            Coverage Diff             @@
##           master      #90      +/-   ##
==========================================
- Coverage   94.01%   93.24%   -0.78%     
==========================================
  Files          20       20              
  Lines         301      311      +10     
  Branches       47       51       +4     
==========================================
+ Hits          283      290       +7     
- Misses         18       21       +3     

codecov-io avatar Jan 05 '21 12:01 codecov-io

I am currently working on fixing the tests.

stz184 avatar Jan 06 '21 20:01 stz184