snamiki1212 / plangoab

Immigration schedule planner with Next.js, Redux, and FullCalendar.js
https://plangoab.snamiki1212.com
GNU General Public License v3.0
9 stars 0 forks source link

Use class in `/core` models #100

Open snamiki1212 opened 3 years ago

snamiki1212 commented 3 years ago

Overview

In terms of the model of core logic in Plangoab, we implemented using not a class but plain JS object because of reason as part of some experiment. However, I finally realized this way is absolutely inferior so going to replace it. https://github.com/snamiki1212/plangoab/blob/main/doc/ARCHITECTURE.md#no-class-but-function

Packages

Choosing below pkg because of handling with Object immutably.

State of Redux

The state of redux can only plain js object so need to convert instance and plain js object when to input/output.

Persist of Redux

Targets

snamiki1212 commented 3 years ago

Once I tried to replace Plain JavaScript Object to Class but it didn't work because we need to think more and a ready for replacing it. I'm listing below what we have to do before going on.

1. Transformer Layer

Redux cannot handle instances of the class so has to use Plain JavaScript Object. UI layer will use Class so we have to create Transform Layer between UI Layer and Redux Layer.

2. Refactor reducer to be a pure function

To begin with, as best practice, reducer should be a pure function( at least should be referential transparency). But, some reducer has a dependency of Model that's meaning we need refactor before replacing tasks. Otherwise, I need to handle complicated tasks when replacing tasks so I want to split each task into small and tackling before going on.


Transformer

snamiki1212 commented 3 years ago
  1. Refactor reducer to be a pure function

https://github.com/snamiki1212/plangoab/issues/99 Done through developing test, as well as fixed to be referencial transparency at least. So we can start this task whenever.