From ac68a837c02ad5178bbe3b9e04cfd16abb9bead4 Mon Sep 17 00:00:00 2001 From: Riley Todd Date: Sat, 18 Jul 2015 16:43:06 -0500 Subject: [PATCH 1/7] Added sequence numbers to generated keys so that they will always be unique --- jsnox.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/jsnox.js b/jsnox.js index 17185b8..e6acb59 100644 --- a/jsnox.js +++ b/jsnox.js @@ -20,6 +20,13 @@ ParseError.prototype.name = 'JSnoXParseError' // from this cache for an increase in performance. var specCache = {} +//An object to hold the count of how many times each key is used +//so far in order to append the count to the key and therefore +//make each key unique. This avoids any +// flattenchildren encountered two children with the same key react +//type of errors +var keyCount = {} + // Convert a tag specification string into an object // eg. 'input:checkbox#foo.bar[name=asdf]' produces the output: // { @@ -42,7 +49,9 @@ function parseTagSpec(specString) { // Provide the specString as a default key, which can always be overridden // by the props hash (for when two siblings have the same specString) var tagName = tagMatch[1] - var props = { key: specString } + keyCount[specString] = keyCount[specString] ? keyCount[specString] + 1 : 1; + var uniqueKey = specString + keyCount[specString] + var props = { key: uniqueKey } var classes = [] if (tagMatch[2]) props.type = tagMatch[2] else if (tagName === 'button') props.type = 'button' // Saner default for