Skip to content

Commit c46be2e

Browse files
committed
Rename ObservableProperty to Property. Add ReadOnlyProperty.
1 parent 7985c91 commit c46be2e

14 files changed

Lines changed: 101 additions & 33 deletions

File tree

samples/Unity.Mvvm.Calc/Assets/Scripts/Models/CalcModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public class CalcModel
2323

2424
public CalcModel(IAppContext appContext)
2525
{
26-
_result = new ObservableProperty<string>(string.Empty);
27-
_expression = new ObservableProperty<string>(string.Empty);
26+
_result = new Property<string>(string.Empty);
27+
_expression = new Property<string>(string.Empty);
2828

2929
_converter = appContext.Resolve<FloatToStrConverter>();
3030
_mathOperations = appContext.Resolve<IReadOnlyDictionary<char, IMathOperation>>();

samples/Unity.Mvvm.Counter/Assets/Scripts/ViewModels/CounterViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public class CounterViewModel : IBindingContext
88
{
99
public CounterViewModel()
1010
{
11-
Count = new ObservableProperty<int>();
12-
ThemeMode = new ObservableProperty<ThemeMode>();
11+
Count = new Property<int>();
12+
ThemeMode = new Property<ThemeMode>();
1313

1414
IncrementCommand = new Command(IncrementCount);
1515
DecrementCommand = new Command(DecrementCount);

samples/Unity.Mvvm.CounterLegacy/Assets/Scripts/ViewModels/CounterViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace ViewModels
55
{
66
public class CounterViewModel : IBindingContext
77
{
8-
private readonly IProperty<int> _count = new ObservableProperty<int>();
8+
private readonly IProperty<int> _count = new Property<int>();
99

1010
public CounterViewModel()
1111
{

samples/Unity.Mvvm.ToDoList/Assets/Scripts/ViewModels/AddTaskDialogViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public class AddTaskDialogViewModel : IBindingContext, IInitializable, IDisposab
1313

1414
public AddTaskDialogViewModel(IAppContext appContext)
1515
{
16+
_taskName = new Property<string>();
1617
_taskBroker = appContext.Resolve<TaskBroker>();
17-
_taskName = new ObservableProperty<string>();
1818

1919
AddTaskCommand = new Command(AddTask, CanAddTask);
2020
}

samples/Unity.Mvvm.ToDoList/Assets/Scripts/ViewModels/MainViewModel.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,30 @@ namespace ViewModels
2121
{
2222
public class MainViewModel : IBindingContext, IDisposable
2323
{
24-
private readonly IDialogsService _dialogsService;
25-
26-
private readonly IProperty<string> _date;
2724
private readonly IProperty<int> _createdTasks;
2825
private readonly IProperty<int> _completedTasks;
29-
3026
private readonly IProperty<bool> _isAddTaskDialogActive;
3127

28+
private readonly IReadOnlyProperty<string> _date;
3229
private readonly IReadOnlyProperty<ObservableCollection<TaskItemViewModel>> _taskItems;
3330

31+
private readonly IDialogsService _dialogsService;
32+
3433
public MainViewModel(IAppContext appContext)
3534
{
3635
_dialogsService = appContext.Resolve<IDialogsService>();
3736

3837
_taskItems =
39-
new ObservableProperty<ObservableCollection<TaskItemViewModel>>(
38+
new ReadOnlyProperty<ObservableCollection<TaskItemViewModel>>(
4039
new ObservableCollection<TaskItemViewModel>());
4140
_taskItems.Value.CollectionChanged += OnTaskItemsCollectionChanged;
4241
ChangeAddTaskDialogVisibilityCommand = new AsyncCommand(ChangeAddTaskDialogVisibility);
4342

44-
_date = new ObservableProperty<string>(GetTodayDate());
45-
_createdTasks = new ObservableProperty<int>(GetCreatedTasksCount(_taskItems.Value));
46-
_completedTasks = new ObservableProperty<int>(GetCompletedTasksCount(_taskItems.Value));
43+
_date = new ReadOnlyProperty<string>(GetTodayDate());
44+
_createdTasks = new Property<int>(GetCreatedTasksCount(_taskItems.Value));
45+
_completedTasks = new Property<int>(GetCompletedTasksCount(_taskItems.Value));
4746

48-
_isAddTaskDialogActive = new ObservableProperty<bool>();
47+
_isAddTaskDialogActive = new Property<bool>();
4948

5049
SubscribeOnTaskAddMessage(appContext.Resolve<TaskBroker>()).Forget();
5150
}

samples/Unity.Mvvm.ToDoList/Assets/Scripts/ViewModels/TaskItemViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ namespace ViewModels
77
{
88
public class TaskItemViewModel : ICollectionItem, IInitializable, IDisposable
99
{
10-
private readonly IProperty<bool> _isDone = new ObservableProperty<bool>();
11-
private readonly IProperty<string> _name = new ObservableProperty<string>();
10+
private readonly IProperty<bool> _isDone = new Property<bool>();
11+
private readonly IProperty<string> _name = new Property<string>();
1212

1313
public TaskItemViewModel()
1414
{

src/UnityMvvmToolkit.Core/ObservableProperty.cs renamed to src/UnityMvvmToolkit.Core/Property.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
namespace UnityMvvmToolkit.Core
77
{
8-
public sealed class ObservableProperty<TType> : IProperty<TType>
8+
public sealed class Property<TType> : IProperty<TType>
99
{
1010
private TType _value;
1111

12-
public ObservableProperty()
12+
public Property() : this(default)
1313
{
1414
}
1515

16-
public ObservableProperty(TType value)
16+
public Property(TType value)
1717
{
1818
_value = value;
1919
}
@@ -50,9 +50,9 @@ private void SetValue(TType value)
5050
ValueChanged?.Invoke(this, value);
5151
}
5252

53-
public static implicit operator ObservableProperty<TType>(TType value)
53+
public static implicit operator Property<TType>(TType value)
5454
{
55-
return new ObservableProperty<TType>(value);
55+
return new Property<TType>(value);
5656
}
5757
}
5858
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using UnityMvvmToolkit.Core.Interfaces;
3+
4+
#pragma warning disable CS0067
5+
6+
namespace UnityMvvmToolkit.Core
7+
{
8+
public sealed class ReadOnlyProperty<TType> : IReadOnlyProperty<TType>
9+
{
10+
public ReadOnlyProperty(TType value)
11+
{
12+
Value = value;
13+
}
14+
15+
public TType Value { get; }
16+
17+
public event EventHandler<TType> ValueChanged;
18+
19+
public static implicit operator ReadOnlyProperty<TType>(TType value)
20+
{
21+
return new ReadOnlyProperty<TType>(value);
22+
}
23+
}
24+
}

src/UnityMvvmToolkit.UnityPackage/Assets/Plugins/UnityMvvmToolkit/Runtime/Core/ObservableProperty.cs renamed to src/UnityMvvmToolkit.UnityPackage/Assets/Plugins/UnityMvvmToolkit/Runtime/Core/Property.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
namespace UnityMvvmToolkit.Core
77
{
8-
public sealed class ObservableProperty<TType> : IProperty<TType>
8+
public sealed class Property<TType> : IProperty<TType>
99
{
1010
private TType _value;
1111

12-
public ObservableProperty()
12+
public Property() : this(default)
1313
{
1414
}
1515

16-
public ObservableProperty(TType value)
16+
public Property(TType value)
1717
{
1818
_value = value;
1919
}
@@ -50,9 +50,9 @@ private void SetValue(TType value)
5050
ValueChanged?.Invoke(this, value);
5151
}
5252

53-
public static implicit operator ObservableProperty<TType>(TType value)
53+
public static implicit operator Property<TType>(TType value)
5454
{
55-
return new ObservableProperty<TType>(value);
55+
return new Property<TType>(value);
5656
}
5757
}
5858
}

src/UnityMvvmToolkit.UnityPackage/Assets/Plugins/UnityMvvmToolkit/Runtime/Core/ObservableProperty.cs.meta renamed to src/UnityMvvmToolkit.UnityPackage/Assets/Plugins/UnityMvvmToolkit/Runtime/Core/Property.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)