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

Use GlobalState, use LocalizationDirection, less var's #1155

Merged
merged 4 commits into from Dec 19, 2023
Merged

Conversation

vnbaaij
Copy link
Collaborator

@vnbaaij vnbaaij commented Dec 19, 2023

As discussed

Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://black-pebble-0dc79cb03-1155.westeurope.3.azurestaticapps.net

examples/Demo/Shared/Components/SiteSettingsPanel.razor Outdated Show resolved Hide resolved
private readonly JsonSerializerOptions JSON_OPTIONS = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
};

[Inject]
private GlobalState GlobalState { get; set; } = default!;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this is a good time to rename GlobalState to something more appropriate?
For me, a "State" is not a color or theme management system. A name like GlobalTheme or GlobalDesign would be more appropriate. No?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think renaming is a good thing to do but it would be a breaking change so not appropriate now.
I like GlobalDesign! Let's reserve that one for when we do want to do the rename. I'll update the source documentation that this is something we are going to do in the next major version.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could create a GlobalDesign class and set Obsolete all usages of GlobalState (but keeping the property). A lot of references?


var themeJSON = await Module.InvokeAsync<string>("addThemeChangeEvent", _dotNetHelper, Id);
var theme = themeJSON == null ? null : JsonSerializer.Deserialize<DataLocalStorage>(themeJSON, JSON_OPTIONS);
string? themeJSON = await Module.InvokeAsync<string>("addThemeChangeEvent", _dotNetHelper, Id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A reason why you changed var to string? and DataLocalStorage? ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like var :).
In VS it displays like this (for me based on my settings, only changed it for the first line):
image

If the type is already known an shown, then why not us it? VS actually does the substitution for you if you double check on the type.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't depend on preferences (like or dislike), but on naming convention 😀
Here's the one we use in many MS projects: https://dvoituron.com/naming-conventions/rules/

image

The code is clearer / aligned with var and it's more " scalable " when the objects (right) evolve.
But it's only a naming convention.

var themeJSON = ...
var theme = ...

@@ -171,7 +178,7 @@ private async Task ApplyLocalStorageValues(DataLocalStorage? theme)
// Mode (Dark / Light / System)
if (!string.IsNullOrEmpty(theme?.Mode))
{
if (!Enum.TryParse<DesignThemeModes>(theme.Mode, true, out var mode))
if (!Enum.TryParse(theme.Mode, true, out DesignThemeModes mode))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same... why did you remove var? :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same..

Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://black-pebble-0dc79cb03-1155.westeurope.3.azurestaticapps.net

@vnbaaij vnbaaij merged commit ffe8c2d into dev Dec 19, 2023
4 checks passed
@vnbaaij vnbaaij deleted the vnbaaij/theme-work branch December 19, 2023 13:33
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

Successfully merging this pull request may close these issues.

None yet

2 participants