Fix bug in store, where not all items were connected properly
This commit is contained in:
parent
057b8d2f46
commit
573a138709
|
@ -349,22 +349,34 @@ function Store(inputData) {
|
|||
|
||||
const stack = _.reduce(items, (stack, item) => {
|
||||
if (stack.length === 0) {
|
||||
// console.log(`push ${item.text} on stack`)
|
||||
return [[item]]
|
||||
}
|
||||
|
||||
const stackIndented = top(stack)[0].indented
|
||||
let stackIndented = top(stack)[0].indented
|
||||
const itemIndented = item.indented
|
||||
|
||||
if (itemIndented > stackIndented) {
|
||||
push(stack, [Object.assign({}, item)])
|
||||
push(stack, [Object.assign({}, item)]) // [ ... ] => [ ..., item ]
|
||||
// console.log(`push ${item.text} on stack`)
|
||||
} else {
|
||||
// console.log(`itemIndented = ${itemIndented}, stackIndented = ${stackIndented}`)
|
||||
while (stack.length > 1 && itemIndented < stackIndented) {
|
||||
let children = top(stack)
|
||||
pop(stack)
|
||||
pop(stack) // [ ..., A ] => [ ... ]
|
||||
stackIndented = top(stack)[0].indented
|
||||
// console.log(`pop stack`)
|
||||
let cur = top(stack)
|
||||
cur[cur.length - 1].children = children
|
||||
// console.log(`set children for ${cur[cur.length-1].text}`)
|
||||
}
|
||||
if (itemIndented === stackIndented) {
|
||||
top(stack).push(Object.assign({}, item))
|
||||
// console.log(`add child ${item.text}`)
|
||||
} else {
|
||||
push(stack, [Object.assign({}, item)])
|
||||
// console.log(`push ${item.text} on stack`)
|
||||
}
|
||||
top(stack).push(Object.assign({}, item))
|
||||
}
|
||||
return stack
|
||||
}, [])
|
||||
|
|
Loading…
Reference in New Issue
Block a user