Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F# unions are not deep-cloned in Solid.createElmishStore #13

Open
ada-waffles opened this issue Dec 18, 2022 · 0 comments
Open

F# unions are not deep-cloned in Solid.createElmishStore #13

ada-waffles opened this issue Dec 18, 2022 · 0 comments

Comments

@ada-waffles
Copy link

If the model/state type used with Solid.createElmishStore contains an F# union, the union value is not deep-cloned. This causes any compile-time immutable values inside the union to be unexpectedly mutated at runtime, and also breaks Solid's granular change detection (since Fable emits unions as classes and Solid stores treat classes atomically).

Currently Util.deepClone only handles values whose runtime type is either an array, an F# record, or a plain JS object. Would it be reasonable to add F# unions to this list?

It does look like union types get a single generated prototype method called cases. In order to not break any emitted code that depends on this, one thought I had would be to, as part of the cloning process, copy all the methods from the object's prototype (as well as maybe Union.prototype and System.Object.prototype) onto the instance. Might make sense to do the same for records, too, so that things like ToString continue to work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant