Skip to content

Commit 4d2297c

Browse files
authored
Added Preview 3 changelog
1 parent 1c5a2f4 commit 4d2297c

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

CHANGELOG.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# API changes in Preview 3:
2+
3+
🆕 New `ObservableValidator` class, which supports the [`INotifyDataErrorInfo`](https://docs.microsoft.com/dotnet/api/system.componentmodel.inotifydataerrorinfo) interface.
4+
5+
🆕 Added new constructors with cancellation support to the async commands, and added new cancellation-related properties to the async command interfaces.
6+
7+
🆕 Added a new `WeakReferenceMessenger` type. This type is less performant than the other messenger, and uses more memory, and in return only uses weak references to track recipients. This type essentially mirrors the behavior of the `Messenger` type from `MvvmLight`, making the transition easier for developers migrating from that library.
8+
9+
🆕 Introduced a new custom delegate to represent message handlers, which also receives the current recipient as additional input parameter. No API changes are required for users registering messages through the `IRecipient<TMessage>` interface, whereas users manually registering will need to modify their code as follows:
10+
11+
```cs
12+
// Preview 2
13+
Messenger.Register<MyMessage>(this, message =>
14+
{
15+
// Do stuff with the message here...
16+
// Note that invoking this instance method means that
17+
// the lambda expression is also capturing "this".
18+
// This issue was also present in MvvmLight.
19+
SomeInstanceMethod();
20+
});
21+
22+
// Preview 3
23+
Messenger.Register<MyViewModel, MyMessage>(this, (recipient, message) =>
24+
{
25+
// Do stuff here...
26+
// Note that since we're accessing the recipient from the
27+
// input parameter, the lambda expression is not capturing
28+
// anything anymore, which allows the C# compiler to cache it.
29+
// Note that we can still access all private members of the
30+
// recipient from here, even if we're using the input parameter.
31+
recipient.SomeInstanceMethod();
32+
});
33+
```
34+
35+
✅ Renamed `Messenger` to `StrongReferenceMessenger`.
36+
37+
✅ The `WeakReferenceMessenger` is now the default messenger used by the `ObservableRecipient` class.
38+
39+
✅ Changed `ObservableObject` overloads using `Expression<Func<T>>` to be more efficient. For instance, the one used to wrap a non-observable model:
40+
41+
```cs
42+
private readonly User user;
43+
44+
public string Name
45+
{
46+
// Preview 2
47+
set => SetProperty(() => user.Name, value);
48+
49+
// Preview 3
50+
set => SetProperty(user.Name, value, user, (u, n) => u.Name = n);
51+
}
52+
```
53+
54+
The syntax is slightly more complex, but results in a 150x speed improvement (that's not a typo), requires no memory allocations at all and no reflection, and ensures that all necessary validation of the arguments can be done at compile time too.
55+
56+
✅ API changes to the `SetPropertyAndNotifyOnCompletion` (as detailed in the blog post).
57+
58+
🚨 Removed the `Ioc` class (we will include docs on how to easily start using the `Microsoft.Extensions.DependencyInjection` library directly to work with dependency injection).
59+
60+
## Notes
61+
62+
For additional info and discussion, see the related issue [here](https://github.com/windows-toolkit/WindowsCommunityToolkit/issues/3428).

0 commit comments

Comments
 (0)