From 801e154d1554ffe9885b56623bf440e3d32f5155 Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Tue, 17 May 2022 07:56:34 -0400 Subject: [PATCH] post-refactor clean up --- .../LibationWinForms/grid/AsyncNotifyPropertyChanged.cs | 2 +- Source/LibationWinForms/grid/GridEntry.cs | 9 --------- Source/_ARCHITECTURE NOTES.txt | 5 ++--- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/Source/LibationWinForms/grid/AsyncNotifyPropertyChanged.cs b/Source/LibationWinForms/grid/AsyncNotifyPropertyChanged.cs index b1711915..cce5e5b9 100644 --- a/Source/LibationWinForms/grid/AsyncNotifyPropertyChanged.cs +++ b/Source/LibationWinForms/grid/AsyncNotifyPropertyChanged.cs @@ -6,7 +6,7 @@ namespace LibationWinForms { public abstract class AsyncNotifyPropertyChanged : SynchronizeInvoker, INotifyPropertyChanged { - // see also notes in Libation/Source/__ARCHITECTURE NOTES.txt :: MVVM + // see also notes in Libation/Source/_ARCHITECTURE NOTES.txt :: MVVM public event PropertyChangedEventHandler PropertyChanged; // per standard INotifyPropertyChanged pattern: diff --git a/Source/LibationWinForms/grid/GridEntry.cs b/Source/LibationWinForms/grid/GridEntry.cs index 07ecb838..b099db3a 100644 --- a/Source/LibationWinForms/grid/GridEntry.cs +++ b/Source/LibationWinForms/grid/GridEntry.cs @@ -76,9 +76,6 @@ namespace LibationWinForms } #endregion - public event EventHandler LibraryBookUpdated; - public event EventHandler Committed; - // alias private Book Book => LibraryBook.Book; @@ -125,9 +122,6 @@ namespace LibationWinForms } UserDefinedItem.ItemChanged += UserDefinedItem_ItemChanged; - - // this will never have a value when triggered by ctor b/c nothing can subscribe to the event until after ctor is complete - LibraryBookUpdated?.Invoke(this, null); } private void PictureStorage_PictureCached(object sender, PictureCachedEventArgs e) @@ -189,9 +183,6 @@ namespace LibationWinForms Book.UserDefinedItem.BookStatus = bookStatus; Book.UserDefinedItem.PdfStatus = pdfStatus; LibraryCommands.UpdateUserDefinedItem(Book); - - // notify - Committed?.Invoke(this, null); } #endregion diff --git a/Source/_ARCHITECTURE NOTES.txt b/Source/_ARCHITECTURE NOTES.txt index 966713fe..092bcbcc 100644 --- a/Source/_ARCHITECTURE NOTES.txt +++ b/Source/_ARCHITECTURE NOTES.txt @@ -9,6 +9,5 @@ see also: https://docs.microsoft.com/en-us/dotnet/desktop/winforms/controls/rais BindingSource + INotifyPropertyChanged + DataGridView is the backbone of our implementation. The SortableBindingList (BindingList/BindingSource) automatically subscribes to each entry's NotifyPropertyChanged -- which is why our AsyncNotifyPropertyChanged.NotifyPropertyChanged is needed even though none of our code calls it. - Adding or removing an entry to/from this BindingSource automatically updates the UI. No additional code needed. -- Updating a field updates the UI via calling NotifyPropertyChanged. - -We break the pattern with updating the book inside of GridEntry. To really follow MVVM, iterate through every bound ("binded"?) field name and call NotifyPropertyChanged. It's much more convenient, quicker, and less error prone to make an exception to MVVM via GridEntry.LibraryBookUpdated => InvalidateRow. The downside is that the view has to wire this up. If we change where in the code we can update the book inside of GridEntry, this dependency will also need to be duplicated in the new place +- Calling NotifyPropertyChanged with the name of a field updates that field in the UI +- Calling NotifyPropertyChanged without a field name (or with an invalid field name) updates the whole entry in the UI