fix array modification

main
Laurin Weger 1 week ago
parent 68f9ec498c
commit 400ba719b5
No known key found for this signature in database
GPG Key ID: 9B372BB0B792770F
  1. 1
      README.md
  2. 15
      src/deepSignal.ts

@ -8,6 +8,7 @@ Core idea: wrap a data tree in a `Proxy` that lazily creates per-property signal
* Lazy: signals & child proxies created only when touched. * Lazy: signals & child proxies created only when touched.
* Deep: nested objects, arrays, Sets proxied on demand. * Deep: nested objects, arrays, Sets proxied on demand.
* [ ] TODO: Methods might not be proxied (e.g. array.push)?
* Per-property signals: fine‑grained invalidation without traversal on each change. * Per-property signals: fine‑grained invalidation without traversal on each change.
* Patch stream: microtask‑batched granular mutations (paths + op) for syncing external stores / framework adapters. * Patch stream: microtask‑batched granular mutations (paths + op) for syncing external stores / framework adapters.
* Getter => computed: property getters become derived (readonly) signals automatically. * Getter => computed: property getters become derived (readonly) signals automatically.

@ -644,8 +644,19 @@ const objectHandlers = {
if (shouldProxy(val)) { if (shouldProxy(val)) {
if (!objToProxy.has(val)) { if (!objToProxy.has(val)) {
// Link newly wrapped child to its parent for path reconstruction. // Link newly wrapped child to its parent for path reconstruction.
const parentMeta = proxyMeta.get(receiver)!; // In some edge cases parent metadata might not yet be initialized (e.g.,
const childProxy = createProxy(val, objectHandlers, parentMeta.root); // if a proxied structure was reconstructed in a way that bypassed the
// original deepSignal root path). Fall back to creating/assigning it.
let parentMeta = proxyMeta.get(receiver);
if (!parentMeta) {
// Assign a root id (new symbol) so downstream patches remain groupable.
const created: ProxyMeta = {
root: Symbol("deepSignalRootAuto"),
} as ProxyMeta;
proxyMeta.set(receiver, created);
parentMeta = created;
}
const childProxy = createProxy(val, objectHandlers, parentMeta!.root);
const childMeta = proxyMeta.get(childProxy)!; const childMeta = proxyMeta.get(childProxy)!;
childMeta.parent = receiver; childMeta.parent = receiver;
childMeta.key = fullKey; childMeta.key = fullKey;

Loading…
Cancel
Save