refactor: Move data structure functions into its own module

This commit is contained in:
Armen Zambrano G 2017-11-07 13:28:03 -05:00 коммит произвёл Armen Zambrano
Родитель 1cc809b2c9
Коммит 5d27536c90
2 изменённых файлов: 12 добавлений и 12 удалений

Просмотреть файл

@ -5,6 +5,7 @@ import ReactInterval from 'react-interval';
// XXX: Create module that fetches ccov data + diff data
import { coverageSummaryText } from './diffviewermeta';
import * as FetchAPI from '../utils/fetch_data';
import { arrayToMap, mapToArray } from '../utils/data';
const PENDING = 'Pending';
@ -54,18 +55,6 @@ const PollingStatus = ({ pollingEnabled }) => (
</div>) : (null)
);
const arrayToMap = (csets) => {
const newCsets = {};
csets.forEach((cset) => {
newCsets[cset.node] = cset;
});
return newCsets;
};
const mapToArray = csets => (
Object.keys(csets).map(node => csets[node])
);
const csetWithCcovData = async (cset) => {
if (!cset.node) {
throw Error(`No node for cset: ${cset}`);

11
src/utils/data.js Normal file
Просмотреть файл

@ -0,0 +1,11 @@
export const arrayToMap = (csets) => {
const newCsets = {};
csets.forEach((cset) => {
newCsets[cset.node] = cset;
});
return newCsets;
};
export const mapToArray = csets => (
Object.keys(csets).map(node => csets[node])
);