Open
Description
- Create tests for src/reducers/network/subnetworks.js. PR reference: Add test for arrows reducer #39
- Refactor src/reducers/network/subnetworks.js.
This issue can ben two PRs but, do the tests first to make sure nothing breaks.
Also, you can use ramda to refactor:
// current
case LOAD_NETWORK: {
const { subnetworks } = action.payload.state.network;
return subnetworks || [];
}
// with Ramda
import { path, defaultTo } from 'ramda';
const pathPayloadStateNetwork = path(['payload', 'state', 'network'])
const defaultToEmptyArray = defaultTo([]);
case LOAD_NETWORK: {
return defaultToEmptyArray(pathPayloadStateNetwork(action))
}
// or
const onLoadNetwork = pipe(pathPayloadStateNetwork, defaultToEmptyArray);
case LOAD_NETWORK: {
return onLoadNetwork(action)
}
Other details about this reducer:
- There is a method called
colorsNol
that should be something likegetRandomColor
. I believe you can extract this to a new utils like/src/utils/colors
or use a package for it. Just to be clear: a super-node is a sub-network that will receive a random color. Yes, I'm awere that super-node is a really bad name but I will change it in another PR. - There is a condition that I don't know if is valid:
if (nodes && positions) {
. This was made because we can receive two different networks: the current format and the old.
In this .zip
you can find the two networks. You can move theses networks to a __fixtures__
folder and then use it in your tests.
first-version-network.json
- the first/legacy versionsimple-network.json
- the current version
Well, thats it 😄