Reactivity for Arrays & Objects in Vue vs. Svelte
Coming from the Vue world, Reactivity in Svelte for anything more than simple strings feels.. a bit different. Vue has made me lazy when handling reactive arrays or objects. All I have to do with the older Object API is - // nums: [1, 2] addToNum() { this.nums.push(this.nums.length + 1); } Directly modifying an element (e.g. this.nums[1] = 'a') would not work though, and that was perfectly fine. It is more tricky for objects - this.planets["jupiter"] = 5 will not trigger reactivity. We could work around this by this.planets = { ...this.planets, jupiter: 5 }. (Or, use $add if you are weird). ...