boyney123 / mockit

A tool to quickly mock out end points, setup delays and more...
https://mockit.netlify.com/
MIT License
1.58k stars 84 forks source link

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

Open stz184 opened 3 years ago

stz184 commented 3 years ago

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.

codecov-io commented 3 years ago

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     
stz184 commented 3 years ago

I am currently working on fixing the tests.