From 94671507b5bb0dc59272affda8ac7ea6cb050f13 Mon Sep 17 00:00:00 2001 From: jos Date: Fri, 26 Aug 2016 13:25:34 +0200 Subject: [PATCH] Prevent duplicate property names --- src/jsonData.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/jsonData.js b/src/jsonData.js index a28987e..abeaf31 100644 --- a/src/jsonData.js +++ b/src/jsonData.js @@ -46,7 +46,10 @@ export function changeProperty (data, path, oldProp, newProp) { const object = getIn(data, dataPath) const index = object.props.findIndex(p => p.name === oldProp) - return setIn(data, dataPath.concat(['props', index, 'name']), newProp) + // prevent duplicate property names + const uniqueNewProp = findUniqueName(newProp, object.props.map(p => p.name)) + + return setIn(data, dataPath.concat(['props', index, 'name']), uniqueNewProp) } /** @@ -173,6 +176,9 @@ export function duplicate (data, path, prop) { const original = props[index] const duplicate = cloneDeep(original) + // prevent duplicate property names + duplicate.name = findUniqueName(duplicate.name, props.map(p => p.name)) + updated.splice(index + 1, 0, duplicate) return updated