Add extension method to detect and isolate realm collection-level changes

This commit is contained in:
Dean Herbert
2022-03-08 14:42:59 +09:00
parent e0d2c8ca5e
commit 2a55c5e02e
2 changed files with 68 additions and 2 deletions

View File

@ -4,6 +4,8 @@
using System;
using Realms;
#nullable enable
namespace osu.Game.Database
{
public static class RealmExtensions
@ -22,5 +24,14 @@ namespace osu.Game.Database
transaction.Commit();
return result;
}
/// <summary>
/// Whether the provided change set has changes to the top level collection.
/// </summary>
/// <remarks>
/// Realm subscriptions fire on both collection and property changes (including *all* nested properties).
/// Quite often we only care about changes at a collection level. This can be used to guard and early-return when no such changes are in a callback.
/// </remarks>
public static bool HasCollectionChanges(this ChangeSet changes) => changes.InsertedIndices.Length > 0 || changes.DeletedIndices.Length > 0 || changes.Moves.Length > 0;
}
}