controls-state
controls-state copied to clipboard
Destructive handling of non-POJOs/primitives (e.g: Array)
It seems that values that aren't primitive or Object
types are destructively handled - for example, if an Array
is passed to a state field, it does not keep its length
property or the other Array
behaviour; instead, it's replaced with a proxy of type Object
.
This makes it hard to use the state objects in a transparent way, as though working with the original values passed in, in these cases.
One solution might be to allow a field type similar to the raw
field, or to keep the original values in-place at each level (not just the primitive level, as is currently stored in the value
get/set property)...?
Example:
State({ test: [0, 1, 2, 3] }).test.length !== [0, 1, 2, 3].length;
Other than this minor frustration, loving these tools!
Hmm… it seems like it shouldn't be too difficult to pass those through directly, without modification.
Is that within the current setup, or do you mean it shouldn't be too difficult a change?
I couldn't work out how to do it with the existing fields, but was thinking maybe it could be passed to the Field
base field (though that's not publicly exported) or something similar to the Raw
field?
I can get some of the way there with the Raw
field, in that it doesn't modify the input value - but I don't get the nice event emitting behaviour.
I can also Object.assign
the input value into some field, but that has the same issue.
Deeply-nested objects would be another case that'd be good to handle - nice to get the event-emitting from deeply-nested children of the input value, while maintaining the input value's original properties.
I mean that would indeed be nice. I don’t currently have the bandwidth to maintain/develop this further, but in more than happy to help out!
Cool, I'll have a little look and see what I can do - thanks!