sprae 13.3.3 → 13.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/store.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * @module sprae/store
4
4
  */
5
5
 
6
- import { signal, computed } from './core.js'
6
+ import { signal, computed, batch } from './core.js'
7
7
 
8
8
  /** Symbol for accessing the internal signals map */
9
9
  export const _signals = Symbol('signals')
@@ -241,8 +241,11 @@ const set = (signals, k, v, wrap = store) => {
241
241
  if (v === _v) return
242
242
  // stashed _set for value with getter/setter
243
243
  if (_s[_set]) return _s[_set](v)
244
- // replace array: create new list store, let :each teardown+recreate
245
- if (Array.isArray(v) && Array.isArray(_v)) _s.value = _change in v ? v : list(v)
244
+ // patch store array in-place to preserve identity (avoids reactive loops when an effect reads + writes same prop)
245
+ if (Array.isArray(v) && Array.isArray(_v)) {
246
+ if (_change in _v) batch(() => { for (let i = 0; i < v.length; i++) _v[i] = v[i]; _v.length = v.length })
247
+ else _s.value = _change in v ? v : list(v)
248
+ }
246
249
  else _s.value = wrap(v)
247
250
  }
248
251