Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getSchema returning undefined doesn't break setIn #269

Merged
merged 6 commits into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/utils/src/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ test('test setIn auto create array', () => {
).toBeTruthy()
})

test('getSchema return undefined', () => {
const value = {}
setIn(value, 'array.0.bb.2', 'hello world', () => {})

expect(
isEqual(value, {
array: [
{
bb: [undefined, undefined, 'hello world']
}
]
})
).toBeTruthy()
})

test('test setIn dose not affect other items', () => {
const value = {
aa: [
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/src/accessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,8 @@ function _setIn(
if (/^\d+$/.test(pathArr[i + 1 + ''])) {
if (getSchema) {
const schema = getSchema(pathArr.slice(0, i) as string[])
if (schema.type === 'array') {

if (!schema || schema.type === 'array') {
obj[p] = []
} else {
obj[p] = {}
Expand Down