Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Refactor data structure to smaller chunks #63

Open
sthiepaan opened this issue Oct 27, 2020 · 2 comments
Open

♻️ Refactor data structure to smaller chunks #63

sthiepaan opened this issue Oct 27, 2020 · 2 comments
Assignees

Comments

@sthiepaan
Copy link
Collaborator

After working on few features/properties for this project, I noticed that it is pretty hard to work with especially when it comes to write tests for API. When we want to compare output of some API methods, we need to duplicate content of data.json file. Another thing is that currently we have JSON file (with almost 5000 lines 😱) and whenever we add/update/remove some property there, it is a bit annoying and hard to check those changes on code review.

What we could do is refactor JSON data file by splitting it to multiple JavaScript files and then using imports/exports to structure it. This way, we can achieve the same thing (having whole data in one) but also we could "build" smaller chunks for testing purposes (instead of duplicating data).

I have some concept how might it look like, but first I would like to see what you think.
Feel free to share your ideas and have an input how we could achieve this!

@sthiepaan sthiepaan self-assigned this Oct 27, 2020
@bhatvikrant
Copy link
Owner

Yes, @sthiepaan I agree with you completely. We need to modularize the codebase.
Testing and PR reviewing processes are kinda hard right now, no doubt about that.

What do you have in mind? Let's list out what all we can do to modularize the codebase.

@sthiepaan
Copy link
Collaborator Author

sthiepaan commented Oct 30, 2020

What we could do at first is basically:

  1. Split data.json to separate JavaScript files for each country individually
    In this case what we could do is for example something like:
...
├  data
│ ├ eu
│ │ ├ pl.js
│ │ └ de.js
│ ├ af
│ │ └ zw.js
...

This allow us to focus only on a specific country or countries for specific continent. We still need to provide properties for all countries to have consistent data model, but I think this could be solved in another way (e.g. Node.js task to add new property to all countries).
The downside of it is that whenever we populate the data, instead of working on a single file, we have to modify multiple files (which should not be a really big deal tho). On the other hand, as we mentioned earlier, the code review is pretty annoying at the moment.

  1. Split index.js to separate JS files for each API Method
    Splitted files, less confusion and whenever we want to add/change/remove a new method, we will not struggle with that many conflicts that we had so far.

  2. Split getCountriesSpec.js to separate JS files for each API Test
    Same as point 2. but for tests. Also, together with 1., this will allow us to reuse data model to compare output of the methods together with different combinations of the data models that we have (no more data repetitions across the project).


In general, we can split the problem into multiple smaller parts. For instance, points 2. and 3. can be done separately.
This way we do not make too big Pull Request, so on the code review we can focus just on one aspect of refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants