-
Notifications
You must be signed in to change notification settings - Fork 113
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
fix: when resetting mode
to the default value (undefined
), the mode switches successfully, but the corresponding menu item is not selected
#424
Conversation
Thanks Cloyd! I think that other places in the code can suffer from similar issues: the TypeScript definition of
Option 2 sounds best to me. What do you think? |
Is option 2 a bit burdensome? Does it require maintaining an additional defaultXXX for each property? export interface JSONEditorPropsOptional {
mode?: Mode
validator?: Validator | null
} I think the And there is a TS compiler option for this situation: https://www.typescriptlang.org/tsconfig#exactOptionalPropertyTypes |
The code indeed uses optional properties and defaults, however you uncovered that these defaults do not always work, so the properties can become |
I submitted some code, though I feel there are definitely omissions, could you make any additions based on this if my understanding is correct? |
Thanks for getting this started! This is indeed the gist of it, though export let defaultMode = Mode.tree
export let mode: Mode | undefined = defaultMode can become: let defaultMode = Mode.tree // No need to export. Also: maybe easier to name it modeDefault?
export let mode: Mode | undefined // no need to fill in a default value And then, we need to apply the same trick for all component properties. |
O: and, we should do this in |
The default values of properties could be used in multiple places, so my latest commit have moved them to a common file. |
Hm, that may be handy, I'm not sure. The defaults are only needed inside If you want I can work out a solution, it's on my list. I'm not sure if I can make it today though. |
Some of the properties are currently defined like |
O, we do have to define the properties like |
Here a start: #426 Still need to work out the details. |
Hmm, my thoughts on this:
If we really need
In conclusion, I'd consider fully removing |
Thanks for your inputs Sam, you have some very good points! First: to me, the I'm not really happy with how #426 is shaping up, because it moves the burden of dealing with For context: I was reading up on sveltejs/svelte#9948 and sveltejs/svelte#9764, about whether a property falls back to its default value when changing it to When looking into option 1, improving
I'm not sure how broad of an issue this is, and it seems that Svelte 5 gets better support for this so after migrating it may be that this issue is solved as a side effect. So maybe for now the approach of 1.1 is best, and when migrating to Svelte 5 (once released) we can look into ensuring the fallback to default values to actually work. |
I recommend not making any changes before upgrading to Svelte 5, reassess after the upgrade. |
Yeah, let's await Svelte 5. (we can already experiment with it if anyone is into it) |
I only reacted to this because of code quality concerns; I don't care about this feature otherwise so I'll not experiment with it. That said, an improvement unrelated to the default values is to rewrite A simple solution for the default values could also be implemented with the following approach:
This approach will:
Note that importing a svelte file from itself might technically not be intended; I've used it in some other projects and it works though... |
Thanks for your inputs Sam! We can indeed improve on I don't see "overriding private internal variables" as a major issue, though it is good to keep it in mind. In most JavaScript code you can easily override methods and public/private variables and even override built-in globals like |
This issue will be addressed via commit 3a2664c as part of the upgrade to Svelte 5. |
Hello Jos, I've found a small issue and I'm sending a PR for your review.
Minimal reproduction for the small issue: