Skip to content

Commit

Permalink
Support deep nested structures for mapMultiRowFields
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Cordeiro committed Nov 11, 2019
1 parent 886c135 commit d2f262c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,29 @@ export const mapMultiRowFields = normalizeNamespace((
const store = this.$store;
const rows = store.getters[getterType](path);

return rows
.map((fieldsObject, index) => Object.keys(fieldsObject).reduce((prev, fieldKey) => {
const fieldPath = `${path}[${index}].${fieldKey}`;
const defineProperties = (fieldsObject, index, path) => {
return Object.keys(fieldsObject).reduce((prev, fieldKey) => {

let fieldPath = index !== false ? `${path}[${index}].${fieldKey}` : `${path}.${fieldKey}`;

return Object.defineProperty(prev, fieldKey, {
get() {
if (typeof fieldsObject[fieldKey] === 'object' && fieldsObject[fieldKey] !== null) {
return defineProperties(fieldsObject[fieldKey], false, fieldPath)
}
return store.getters[getterType](fieldPath);
},
set(value) {
store.commit(mutationType, { path: fieldPath, value });
},
});
}, {}));
}, {})
};

return rows
.map((fieldsObject, index) => {
return defineProperties(fieldsObject, index, path)
});
},
};

Expand Down

0 comments on commit d2f262c

Please sign in to comment.