[Feature]: Add TransformVirtual Extensions for IObservableList and IObservableCache
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 47/100
Hướng nghiên cứu
Read the existing Transform operator and the IObservableList/IObservableCache interfaces, then inspect how Connect and Preview expose change sets. Implementations are shown for IObservableList, but the issue does not identify repository files or tests, and the cache behavior still needs working out. Done means both extensions expose virtual transformed views with the described access, subscription, and disposal behavior; add tests for list and cache behavior.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the functionality desired 🐞
New extension methods TransformVirtual<TSource, TResult>(Func<TSource, TResult> transformFactory) for IObservableList<TSource> and IObservableCache<TSource, TKey> that create lightweight views of type IObservableList<TResult>/IObservableCache<TResult, TKey> without intermediate storage collection.
There's an implementation for IObservableList I created and used in my project:
public static class CollectionExtensions
{
extension<T>(IReadOnlyList<T> source)
{
public IReadOnlyList<TResult> TransformVirtual<TResult>(Func<T, TResult> transformFactory)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(transformFactory);
return new ReadOnlyListTransformVirtual<T, TResult>(source, transformFactory);
}
}
private sealed class ReadOnlyListTransformVirtual<TSource, TResult> : IReadOnlyList<TResult>
{
private readonly IReadOnlyList<TSource> _source;
private readonly Func<TSource, TResult> _transformFactory;
public ReadOnlyListTransformVirtual(IReadOnlyList<TSource> source, Func<TSource, TResult> transformFactory)
{
_source = source;
_transformFactory = transformFactory;
}
public TResult this[int index] => _transformFactory(_source[index]);
public int Count => _source.Count;
public IEnumerator<TResult> GetEnumerator() => _source.Select(x => _transformFactory(x)).GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}
public static class ObservableListExtensions
{
extension<T>(IObservableList<T> source) where T : notnull
{
public IObservableList<TResult> TransformVirtual<TResult>(Func<T, TResult> transformFactory) where TResult : notnull
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(transformFactory);
return new ObservableListTransformVirtual<T, TResult>(source, transformFactory);
}
}
private sealed class ObservableListTransformVirtual<TSource, TResult> : IObservableList<TResult>
where TSource : notnull
where TResult : notnull
{
private readonly IObservableList<TSource> _source;
private readonly Func<TSource, TResult> _transformFactory;
public ObservableListTransformVirtual(IObservableList<TSource> source, Func<TSource, TResult> transformFactory)
{
_source = source;
_transformFactory = transformFactory;
}
public int Count => _source.Count;
public IObservable<int> CountChanged => _source.CountChanged;
public IReadOnlyList<TResult> Items => _source.Items.TransformVirtual(_transformFactory);
public void Dispose()
{
}
public IObservable<IChangeSet<TResult>> Connect(Func<TResult, bool>? predicate = null)
{
var ret = _source.Connect().Transform(_transformFactory);
if (predicate is not null)
{
ret = ret.Filter(predicate);
}
return ret;
}
public IObservable<IChangeSet<TResult>> Preview(Func<TResult, bool>? predicate = null)
{
var ret = _source.Preview().Transform(_transformFactory);
if (predicate is not null)
{
ret = ret.Filter(predicate);
}
return ret;
}
}
}
Sincerely thank all of you for creating DynamicData!
The steps the functionality will provide
From the end-user perspective:
- Call the new extension method
TransformVirtualon anyIObservableList/IObservableCacheto create another statelessIObservableList/IObservableCacheas a projected view without intermediate storage collection in a fluent way. - Transformation execution is on-demand and should be pure (no side effects). The
transformFactorywill run if items are accessed via indexer or enumeration. There is no precomputation or materialization, unless a subscription of a downstream observer viaConnectorPreviewoccurs. - Disposal of the returned
IObservableList/IObservableCacheis not required and does nothing because it's just a stateless wrapper. - Fully compatible with consumer scenarios that require direct index access, count property and enumeration support.
Considerations
Currently, in order to transform the elements of an IObservableList/IObservableCache, the Connect method needs to be called first and then use the Transform operator of observable change set. After that, the type of the current operating object becomes observable change set and the direct accessors of collection count and items are lost. In some cases, SourceList/SourceCaches are internally used and some transformed IObservableList/IObservableCaches should be exposed as public API. To revert to IObservableList/IObservableCache type, the method AsObservableList/AsObservableCache can be used, which creates intermediate storage collection (e.g. SourceList is created for IObservableList). If we just want to do a simple transformation, such as a type cast (even the implicit cast because covariance is not supported by DynamicData), this method is inefficient and unnecessary. To do this in a better way, we can just create a stateless wrapper of IObservableList/IObservableCache without inherent subscription and collection allocation.
- Ngôn ngữ chính
- C#
- Star
- 1.9k
- Fork
- 194
- Merge trung bình
- 12 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của reactivemarbles/DynamicData
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
reactivemarbles/DynamicData#1229 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
infrastructure
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
reactivemarbles/DynamicData#1089 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: ChangeAwareList merges an insert one slot before a pending AddRange, corrupting list order downstreamCó thể đã có người làm @dwcullop đã nhận 9 ngày trước. Đang mởbug
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 63/100
reactivemarbles/DynamicData#1225 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Feature]: Make Avg, StdDev, Maximum and Minimum refresh-aware, consistent with SumCó thể đã có người làm @dwcullop đã nhận 14 ngày trước. Đang mởbreaking change enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
reactivemarbles/DynamicData#1214 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
reactivemarbles/DynamicData#1196 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của reactivemarbles/DynamicData
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
immichFrame/ImmichFrame#735 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
dimitar-radenkov/Pointframe#318 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
DotHarness/dotcraft#546 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
a-corriger bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
christian-raj/S-Aloha#303 · 1 bình luận ·
-
Input editor says "Apply Changes" even when no changes have been made.Có thể đã có người làm @hcooper đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
MobiFlight/MobiFlight-Connector#3526 ·
Maintainer thường phản hồi trong vòng 1 ngày