Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for firing add event for initial elements #20

Merged
merged 1 commit into from
Feb 15, 2024

Conversation

hadashiA
Copy link
Contributor

@hadashiA hadashiA commented Feb 1, 2024

When an AttachFilter is executed, CollectionChangeEvent will not fire for elements that already exist.
(WhenTrue/WhenFalse will fire)

If you are performing some destructive operation on a View (GameObject, etc.) with a CollectionChangeEvent, it may be bad if you cannot apply the same process to an already existing element.

So I added the following overload:

  • AttachFilter<>(filter, bool invokeAddEventForInitialElements = false)

( It may not be a very pretty solution..)

filter.InvokeOnAttach(value, view);
if (invokeAddEventForCurrentElements)
{
filter.InvokeOnAdd(value, view, NotifyCollectionChangedEventArgs<T>.Add(value, -1));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could not support getting the index of the SortedView source here.

In the current implementation, the index that can be obtained with ISynchronizedViewFilter.OnCollectionChanged is, from the source of IObservableCollection.
However, perhaps it should be the index of the ISynchronizedView (?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If #22 is adopted, indexes can be supported.

@neuecc neuecc merged commit eff61e9 into master Feb 15, 2024
2 checks passed
@neuecc neuecc deleted the hadashiA/initial-elements-add branch February 15, 2024 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants