GumusLab / clustergrammer

WebGL Clustergrammer JavaScript Library
https://ismms-himc.github.io/clustergrammer-gl/
MIT License
2 stars 9 forks source link

Reducers - handle state gracefully #37

Open tschaka1904 opened 2 years ago

tschaka1904 commented 2 years ago

There are a bunch of reducers under src/state/reducers. Whilst they seem to be working fine, they don't seem to align with the redux/react docs entirely.

There are 3 areas where improvement could be done:

  1. Remove unnecessary state = * assignment. We shouldn't mutate the state.
  2. _.merge mutates the state. It should be merge({}, state, action.payload) (Caution: This is rather expensive. Maybe immutable-ops#deepMerge is an option)
  3. Remove unnecessary return state, as the reducer takes care of it. Only in cases where we want action.payload to replace the state we should return action.payload.

Further thoughts: Maybe, the reducers could be a little more detailed. Just to avoid to have to deal with functionalities like _.merge. If we would know where the change needs to be applied, we could probably get rid of the merge functionality. This would help the state (and any re-render).

tschaka1904 commented 2 years ago

This should mostly be addressed in #38 #39