Skip to content

Commit

Permalink
* 🐛 fix #213 list notation always doing {*} (#217)
Browse files Browse the repository at this point in the history
* ✅ Add a test for bug #213

* 🐛 fix #213 list notation always doing {*}, improve tests
  • Loading branch information
nlepage committed Jan 16, 2018
1 parent 3083de7 commit 2e69868
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/immutadot/src/path/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const apply = operation => {
const newObj = copy(curObj, false)
let noop = true

const listProps = allProps ? Object.keys(newObj) : propValue
const listProps = propType === allProps ? Object.keys(newObj) : propValue

for (const listProp of listProps) {
const [iNoop] = walkPath(newObj, curPath, [[prop, listProp], ...pathRest], true)
Expand Down
24 changes: 24 additions & 0 deletions packages/immutadot/src/path/apply.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ describe('path.apply', () => {
'prop2': { val: 6 },
'prop{3}': { val: 6 },
'"prop4"': { val: 4 },
'prop5': { val: 5 },
},
other: {},
})
Expand All @@ -180,6 +181,7 @@ describe('path.apply', () => {
'prop2': { val: 5 },
'prop{3}': { val: 5 },
'"prop4"': { val: 3 },
'prop5': { val: 5 },
},
other: {},
},
Expand Down Expand Up @@ -242,4 +244,26 @@ describe('path.apply', () => {
'nested.prop',
)
})

it('should initialize unknown props in a list', () => {
immutaTest(
input => {
const output = inc(input, 'nested.{prop1,prop2}.val')
expect(output).toEqual({
nested: {
prop1: { val: 6 },
prop2: { val: 1 },
},
other: {},
})
return output
},
{
nested: { prop1: { val: 5 } },
other: {},
},
'nested.prop1.val',
'nested.prop2.val',
)
})
})

0 comments on commit 2e69868

Please sign in to comment.