sprae 13.3.3 → 13.3.5

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, untracked } from './core.js'
7
7
 
8
8
  /** Symbol for accessing the internal signals map */
9
9
  export const _signals = Symbol('signals')
@@ -221,6 +221,7 @@ const create = (signals, k, v, wrap = store) => (signals[k] = (k[0] == '_' || v?
221
221
  /** Lightweight reactive wrapper for array items — avoids full store() per item. */
222
222
  const shallow = (v) => {
223
223
  if (!v || typeof v !== 'object' || v.constructor !== Object) return v
224
+ if (v[_change]) return v // already reactive (store or shallow proxy)
224
225
  let ver = signal(0)
225
226
  return new Proxy(v, {
226
227
  get: (t, k) => k === _signals ? t : k === _change ? ver : (ver.value, t[k]),
@@ -241,8 +242,11 @@ const set = (signals, k, v, wrap = store) => {
241
242
  if (v === _v) return
242
243
  // stashed _set for value with getter/setter
243
244
  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)
245
+ // patch store array in-place to preserve identity (avoids reactive loops when an effect reads + writes same prop)
246
+ if (Array.isArray(v) && Array.isArray(_v)) {
247
+ if (_change in _v) untracked(() => batch(() => { for (let i = 0; i < v.length; i++) _v[i] = v[i]; _v.length = v.length }))
248
+ else _s.value = _change in v ? v : list(v)
249
+ }
246
250
  else _s.value = wrap(v)
247
251
  }
248
252
 
@@ -1 +1 @@
1
- {"version":3,"file":"each.d.ts","sourceRoot":"","sources":["../../directive/each.js"],"names":[],"mappings":"AA8Be;;;;EAuHd;;qBArJ6F,YAAY"}
1
+ {"version":3,"file":"each.d.ts","sourceRoot":"","sources":["../../directive/each.js"],"names":[],"mappings":"AAuBe;;;;EAiHd;;qBAxI6F,YAAY"}