Skip to content

Commit 437645d

Browse files
committed
Fix object array field mobx persistence
1 parent 0f9c8c4 commit 437645d

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/util/mobx-persist/types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ import {
66
} from 'serializr'
77

88
function _walk(v: any) {
9-
if (typeof v === 'object' && v) Object.keys(v).map(k => _walk(v[k]))
9+
if (typeof v === 'object' && v) {
10+
if (Array.isArray(v)) {
11+
// Make sure we read .length as well as values to observe
12+
// the array even if it's empty.
13+
for (let i = 0; i < v.length; i++) _walk(v[i]);
14+
} else {
15+
Object.keys(v).map(k => _walk(v[k]));
16+
}
17+
}
1018
return v
1119
}
1220

0 commit comments

Comments
 (0)