Skip to content

Commit ef875a1

Browse files
authored
Replace usage of Map for result with Object
It is impractical to iterate over a Map, so let's use an Object for now.
1 parent 01fab7b commit ef875a1

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ const [firstStats, secondStats] = await Promise.all([
1414
);
1515
const changes = differ(firstStats, secondStats);
1616

17-
//=> Returns a Map with all changes
18-
// Map {
19-
// 'values.colors.unique' => [
17+
//=> Returns an object with all changes
18+
// {
19+
// 'values.colors.unique': [
2020
// {
2121
// value: 'brown',
2222
// removed: true,

diff.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ const diffLists = require('./src/diff-lists.js')
44
function diffStats(statsA, statsB) {
55
// This assumes that the statsB is newer than statsA
66
return Object.entries(statsB).reduce((diff, [key, value]) => {
7-
return diff.set(key, diffStat(statsA[key], value))
8-
}, new Map())
7+
diff[key] = diffStat(statsA[key], value)
8+
return diff
9+
}, {})
910
}
1011

1112
function diffStat(statA, statB) {

test/diff.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ test('An error is thrown if incompatible stat types are given', t => {
2222
// of the structure is done in other tests
2323
test('It should return the correct structure', t => {
2424
const result = diff(defaultFixture, fixtureWithUpdatedValues)
25-
t.true(result instanceof Map)
26-
t.deepEqual(['a', 'b'], [...result.keys()])
25+
t.is('object', typeof result)
26+
t.deepEqual(['a', 'b'], Object.keys(result))
2727

28-
result.forEach(stat => {
28+
Object.values(result).forEach(stat => {
2929
t.is('boolean', typeof stat.changed)
3030
})
3131
})
3232

3333
test('It should return the correct structure when new props are added', t => {
3434
const result = diff(defaultFixture, fixtureWithAddedProp)
35-
t.deepEqual(['a', 'b', 'c'], [...result.keys()])
35+
t.deepEqual(['a', 'b', 'c'], Object.keys(result))
3636
})

0 commit comments

Comments
 (0)