Cysharp / ObservableCollections

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

WritableView Implementation #75

Closed zerodev1200 closed 1 month ago

zerodev1200 commented 1 month ago

Issues with WritableView Implementation

1. Environment

2. Exception When Editing Empty Row in DataGrid

Issue Description

Additional Observations

3. Unexpected Behavior with WritableView Filter

Added the following code to ObservableCollections.sandbox.ConsoleApp

Reproduction Code

notify[1] = "99999";
view.AttachFilter(x => x % 2 == 0);
Console.WriteLine("view");
foreach (var item in view)
{
    Console.WriteLine(item);
}
Console.WriteLine("");
Console.WriteLine("l(source)");
foreach (var item in l)
{
    Console.WriteLine(item);
}

Current Output

view
0
99999
4

l(source)
0
99999
2
3
4
5

Expected Output

view
0
4

l(source)
0
1
99999
3
4
5

4. Related Improvements

neuecc commented 1 month ago

Thank you, I've released 3.1.1, that fixed these issues.

2: I've implement Add operation for WritableNotifyCollectionChanged

Usage example:

IList<string?> bindable = view.ToWritableNotifyCollectionChanged((string? newView, Person original, ref bool setValue) =>
{
    if (setValue)
    {
        // default setValue == true is Set operation
        original.Name = newView;

        // You can modify setValue to false, it does not set original collection to new value.
        // For mutable reference types, when there is only a single,
        // bound View and to avoid recreating the View, setting false is effective.
        // Otherwise, keeping it true will set the value in the original collection as well,
        // and change notifications will be sent to lower-level Views(the delegate for View generation will also be called anew).
        setValue = false;
        return original;
    }
    else
    {
        // default setValue == false is Add operation
        return new Person { Age = null, Name = newView };
    }
});

3: It is bug! I've fixed!

zerodev1200 commented 1 month ago

Thank you! However, I'm currently investigating because there's an exception occurring in WPF and it's not working properly...

zerodev1200 commented 1 month ago

I may have seen a glimmer of hope. I'll investigate a bit more and submit a PR...!

neuecc commented 1 month ago

thanks, v3.3.0 includes your PR!