Cysharp / ObservableCollections

High performance observable collections and synchronized views, for WPF, Blazor, Unity.
MIT License
535 stars 43 forks source link

How to use ViewChanged event? #69

Closed lsenala closed 1 week ago

lsenala commented 1 week ago

Because the documentation was poorly explained, I spent three days trying to figure out what mvvm was and whether it was the same mvvm as in the documentation. The conclusion is that it is not. Judging from the arrow pointing in the document, it looks more like MVC, but strangely it uses the word viewmodel. I am using Unity, which seems to be unable to use mvvm except for app UI, so I don’t know the significance of the recommendation to use CreateView in the document? I don't know how to use ViewChanged. Subscribe to the event and access the NotifyCollectionChangedAction Action. The result is always reset, and there is no useful information. The code is shown below. In addition, CreateView uses a foreach loop and cannot use iterators to perform calculations in the loop. Local variables need to be declared outside the CreateVIew function. Is this ISynchronizedView a viewmodel, a view, or something else customized. I have no idea. 112

neuecc commented 1 week ago

MVVM is a pattern commonly used in UI frameworks like WPF, Angular, Android, etc... That's correct, and in Unity, the MVP pattern is more commonly used. In that case, you can think of the VM as P (Presenter), and the meaning is more or less the same.

There's no need to force its use.

If you only need update notifications, using events or combining with R3 might be sufficient. In Unity, since data binding is not available, the View is often not as convenient to use (because there are parts that need to be manually handled via events, which can feel unnatural).

neuecc commented 1 week ago

Oh, but the sample was wrong. Adding to the root should be done in the func, not with Add. This is a mistake that occurred because I took the code example from the previous version as it was, so I'm sorry.