fix(reactivity): keep previous effect scope

This commit is contained in:
三咲智子 Kevin Deng 2024-02-03 06:15:46 +08:00
parent be65b98a33
commit 8dec243dc1
No known key found for this signature in database
GPG Key ID: 69992F2250DFD93E
2 changed files with 11 additions and 5 deletions

View File

@ -62,11 +62,13 @@ export class EffectScope {
} }
} }
prevScope: EffectScope | undefined
/** /**
* This should only be called on non-detached scopes * This should only be called on non-detached scopes
* @internal * @internal
*/ */
on() { on() {
this.prevScope = activeEffectScope
activeEffectScope = this activeEffectScope = this
} }
@ -75,7 +77,7 @@ export class EffectScope {
* @internal * @internal
*/ */
off() { off() {
activeEffectScope = this.parent activeEffectScope = this.prevScope
} }
stop(fromParent?: boolean) { stop(fromParent?: boolean) {

View File

@ -23,12 +23,16 @@ export default defineComponent({
const container = document.createElement('li') const container = document.createElement('li')
append(container, node) append(container, node)
const update = () => { renderEffect(() => {
const [item, index] = block.s const [item, index] = block.s
node.textContent = `${index}. ${item}` node.textContent = `${index}. ${item}`
} })
renderEffect(update)
return [container, update] renderEffect(() => {
const [item, index] = block.s
node.textContent = `${index}/ ${item}`
})
return container
}, },
(item, index) => index, (item, index) => index,
) )