deepsignal icon indicating copy to clipboard operation
deepsignal copied to clipboard

Question: has using a Proxy been considered to prevent (unintentional) mangling of the deepSignal instances?

Open p-bakker opened this issue 1 year ago • 0 comments

DeepSignal instances expose the properties of the wrapped state object directly as signal or DeepSignal instances.

This allows a novice developer to easily overwrite/alter the (deep)Signal values by mistake when attempting to update the underlying value

For example using this as the setup:

import { deepSignal } from "@deepsignal/react";

const userStore = deepSignal({
  name: {
    first: "Thor",
    last: "Odinson"
  },
  email: "[email protected]"
});

A dev might attempt to update the first name by using userStore.name.first = 'somethingElse';, which would override the signal value or might set a property which wasn't part of the initial payload like userStore.age = 30

By wrapping the deepSignal instance in a proxy, the setting of properties could be intercepted and something like userStore.name.first = 'somethingElse'; could either throw an error or underwater set userStore.name.first.value instead and non-existing properties/paths could be properly handled

p-bakker avatar Jan 14 '25 08:01 p-bakker