-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Summary
As a side-effect of how stores are made (proxy objects), when you set a property of a store to another store's property (for example, when managing a saved state), you get the reference to the other store, not it's value:
const workingStore = useStore({ numbers: [1,2,3,4] });
const savedStore = useStore({ numbers: [1,2,3] });
const onSave = () => {
// doesn't just update the value, sets the proxy pointer!
savedStore.numbers = workingStore.numbers
}This can be worked around by either of the following ways:
- deconstruct the value into raw data, e.g. using
[...workingStore.numbers] - expose the
raw()function that the observable library provides
The first solution can be cumbersome an error prone, as the store structure gets larger or more complicated.
The second solution could lead to misuse / confusion on how stores work - up until this point they are treated as black-box objects that "just work", exposing a raw() function could lead to people interacting with that more than they should, in ways they really shouldn't / don't need to.
Conversely, exposing the raw() function could also be really really useful for debugging purposes, right now it is somewhat non-trivial to inspect a the proxy-observable store, but this would make it much easier.