Skip to content

Commit b1244ee

Browse files
committed
refactor(life-cycle): simplify how numbers are composed
1 parent 57358d5 commit b1244ee

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

Diff for: src/shared/commitChanges.js

+21-26
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
11
import { add } from './math'
22

3-
// Update the store with the time spent while committing the changes
4-
const updateStore = (store, measure, delimiter) => {
5-
if (measure.name.includes(delimiter)) {
6-
const measureName = measure.name.split(delimiter).join('')
3+
const COMMITTING_CHANGES = 'Committing Changes'
4+
const LIFE_CYCLE_NOTICE = '⚛'
5+
const RECONCILIATION_NOTICE = '⛔'
76

8-
if (measureName.includes('(Committing Changes)')) {
9-
if (!store['Committing Changes']) {
10-
store['Committing Changes'] = {
11-
timeSpent: []
12-
}
13-
}
7+
const getMeasurmentsByDelimiter = (measurments, delimiter) =>
8+
measurments
9+
.filter(
10+
measurment =>
11+
measurment.name.includes(delimiter) &&
12+
measurment.name
13+
.split(delimiter)
14+
.join('')
15+
.includes(COMMITTING_CHANGES)
16+
)
17+
.map(measurment => Number(measurment.duration.toFixed(2)))
1418

15-
store['Committing Changes'].timeSpent.push(
16-
Number(measure.duration.toFixed(2))
17-
)
18-
}
19+
const getCommitChangesTime = measurements => ({
20+
[COMMITTING_CHANGES]: {
21+
timeSpent: [
22+
...getMeasurmentsByDelimiter(measurements, LIFE_CYCLE_NOTICE),
23+
...getMeasurmentsByDelimiter(measurements, RECONCILIATION_NOTICE)
24+
]
1925
}
20-
}
21-
22-
const getCommitChangesTime = measures => {
23-
let store = {}
24-
25-
for (const measure of measures) {
26-
updateStore(store, measure, '⚛')
27-
updateStore(store, measure, '⛔')
28-
}
29-
30-
return store
31-
}
26+
})
3227

3328
export { getCommitChangesTime }

0 commit comments

Comments
 (0)