Skip to content

Instantly share code, notes, and snippets.

@lyleunderwood
Forked from csclyde/Reduce.js
Last active November 22, 2017 21:48
Show Gist options
  • Save lyleunderwood/3f156fe42192fdb1851a81c70a40c5b4 to your computer and use it in GitHub Desktop.
Save lyleunderwood/3f156fe42192fdb1851a81c70a40c5b4 to your computer and use it in GitHub Desktop.
groupsCalculated: (state) => {
const buildNetwork = (connection) => ({ service_id: connection.service_id, login_id: connection.login_id });
const connectionWithNetwork = (conn, net) => ({ ...conn, networks: [...conn.networks, buildNetwork(net)] });
const buildConnection = (conn) => ({ name: conn.name, id: conn.id, networks: [] });
return Object.values(state.all.reduce((acc, curr) => (acc[curr.name] ?
{ ...acc, [curr.name]: connectionWithNetwork(acc[curr.name], curr) } :
{ ...acc, [curr.name]: connectionWithNetwork(buildConnection(curr), curr) }
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment