Skip to content

Commit

Permalink
fix: fix nextBlock get error
Browse files Browse the repository at this point in the history
  • Loading branch information
nooooooom committed Jul 15, 2021
1 parent 260becc commit e2404f6
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/directives/for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,20 @@ export const _for = (el: Element, exp: string, ctx: Context) => {
}

let i = childCtxs.length
let nextBlock: Block | undefined
while (i--) {
const childCtx = childCtxs[i]
const oldIndex = prevKeyToIndexMap.get(childCtx.key)
const next = childCtxs[i + 1]
const nextBlockOldIndex = next && prevKeyToIndexMap.get(next.key)
const nextBlock =
nextBlockOldIndex == null ? undefined : blocks[nextBlockOldIndex]
let block
if (oldIndex == null) {
// new
nextBlocks[i] = mountBlock(
block = mountBlock(
childCtx,
nextBlock ? nextBlock.el : anchor
)
} else {
// update
const block = (nextBlocks[i] = blocks[oldIndex])
block = blocks[oldIndex]
Object.assign(block.ctx.scope, childCtx.scope)
if (oldIndex !== i) {
// moved
Expand All @@ -156,6 +154,7 @@ export const _for = (el: Element, exp: string, ctx: Context) => {
}
}
}
nextBlocks.unshift(nextBlock = block)
}
blocks = nextBlocks
}
Expand Down

0 comments on commit e2404f6

Please sign in to comment.