Skip to content

Commit

Permalink
Merge pull request #67 from lightning-js/feature/assign-array-in-forloop
Browse files Browse the repository at this point in the history
Added support for assigning an array used in a forloop.
  • Loading branch information
michielvandergeest authored Feb 22, 2024
2 parents 59bfe57 + 782898f commit 5e313d4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lib/reactivity/reactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ const reactiveProxy = (target) => {
set(target, key, value, receiver) {
const oldValue = target[key]

const result = Reflect.set(target, key, value, receiver)
let result
if (typeof value === 'object' && Array.isArray(value) && proxyMap.get(target[key])) {
result = target[key].splice(0, target[key].length, ...value)
} else {
result = Reflect.set(target, key, value, receiver)
}

if (typeof result === 'object') {
if (typeof value === 'object') {
reactiveProxy(target[key])
}

Expand Down Expand Up @@ -104,6 +109,7 @@ const reactiveDefineProperty = (target) => {
return internalValue
},
set(newValue) {
// todo: support assigning array (as we do with proxies)
let oldValue = internalValue
if (oldValue !== newValue) {
internalValue = newValue
Expand Down

0 comments on commit 5e313d4

Please sign in to comment.