mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-04-04 03:23:05 -06:00
Improve WatchProperty
This commit is contained in:
parent
1f189e5206
commit
295f4cf9a2
|
|
@ -56,11 +56,9 @@ public class App : Application, IDisposable
|
|||
.GetRequiredService<SettingsService>()
|
||||
.WatchProperty(
|
||||
o => o.Theme,
|
||||
() =>
|
||||
v =>
|
||||
{
|
||||
RequestedThemeVariant = _services
|
||||
.GetRequiredService<SettingsService>()
|
||||
.Theme switch
|
||||
RequestedThemeVariant = v switch
|
||||
{
|
||||
ThemeVariant.Light => Avalonia.Styling.ThemeVariant.Light,
|
||||
ThemeVariant.Dark => Avalonia.Styling.ThemeVariant.Dark,
|
||||
|
|
|
|||
|
|
@ -14,18 +14,12 @@ public partial class LocalizationManager : ObservableObject, IDisposable
|
|||
|
||||
public LocalizationManager(SettingsService settingsService)
|
||||
{
|
||||
_eventRoot.Add(
|
||||
settingsService.WatchProperty(
|
||||
o => o.Language,
|
||||
() => Language = settingsService.Language,
|
||||
true
|
||||
)
|
||||
);
|
||||
_eventRoot.Add(settingsService.WatchProperty(o => o.Language, v => Language = v, true));
|
||||
|
||||
_eventRoot.Add(
|
||||
this.WatchProperty(
|
||||
o => o.Language,
|
||||
() =>
|
||||
_ =>
|
||||
{
|
||||
foreach (var propertyName in EnglishLocalization.Keys)
|
||||
OnPropertyChanged(propertyName);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ internal static class NotifyPropertyChangedExtensions
|
|||
{
|
||||
public IDisposable WatchProperty<TProperty>(
|
||||
Expression<Func<TOwner, TProperty>> propertyExpression,
|
||||
Action callback,
|
||||
Action<TProperty> callback,
|
||||
bool watchInitialValue = false
|
||||
)
|
||||
{
|
||||
|
|
@ -20,6 +20,8 @@ internal static class NotifyPropertyChangedExtensions
|
|||
if (memberExpression?.Member is not PropertyInfo property)
|
||||
throw new ArgumentException("Provided expression must reference a property.");
|
||||
|
||||
var getValue = propertyExpression.Compile();
|
||||
|
||||
void OnPropertyChanged(object? sender, PropertyChangedEventArgs args)
|
||||
{
|
||||
if (
|
||||
|
|
@ -27,14 +29,14 @@ internal static class NotifyPropertyChangedExtensions
|
|||
|| string.Equals(args.PropertyName, property.Name, StringComparison.Ordinal)
|
||||
)
|
||||
{
|
||||
callback();
|
||||
callback(getValue(owner));
|
||||
}
|
||||
}
|
||||
|
||||
owner.PropertyChanged += OnPropertyChanged;
|
||||
|
||||
if (watchInitialValue)
|
||||
callback();
|
||||
callback(getValue(owner));
|
||||
|
||||
return Disposable.Create(() => owner.PropertyChanged -= OnPropertyChanged);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,14 +53,14 @@ public partial class DashboardViewModel : ViewModelBase
|
|||
_eventRoot.Add(
|
||||
Progress.WatchProperty(
|
||||
o => o.Current,
|
||||
() => OnPropertyChanged(nameof(IsProgressIndeterminate))
|
||||
_ => OnPropertyChanged(nameof(IsProgressIndeterminate))
|
||||
)
|
||||
);
|
||||
|
||||
_eventRoot.Add(
|
||||
SelectedChannels.WatchProperty(
|
||||
o => o.Count,
|
||||
() => ExportCommand.NotifyCanExecuteChanged()
|
||||
_ => ExportCommand.NotifyCanExecuteChanged()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue