Skip to content

Commit

Permalink
Added support for direct assignment of an array element and triggerin…
Browse files Browse the repository at this point in the history
…g reactivity.
  • Loading branch information
michielvandergeest committed Apr 10, 2024
1 parent 586cb24 commit 8c2decd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/lib/reactivity/effect.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const track = (target, key) => {
}

export const trigger = (target, key, force = false) => {
if (paused) return
const effectsMap = objectMap.get(target)
if (!effectsMap) {
return
Expand Down
6 changes: 5 additions & 1 deletion src/lib/reactivity/reactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ const reactiveProxy = (original, _parent = null, _key) => {
result = Reflect.set(target, key, value, receiver)
}

if (result && oldRawValue !== value) {
if (result && oldRawValue !== rawValue) {
// if we're assigning an array key directly trigger reactivity on the parent key as well
if (Array.isArray(target) && key in target) {
trigger(_parent, _key, true)
}
trigger(target, key, true)
}
return result
Expand Down

0 comments on commit 8c2decd

Please sign in to comment.