Some comments

This commit is contained in:
Justin Swanson 2019-10-13 01:38:51 -05:00
parent 8478904e67
commit 00ed32f929
2 changed files with 31 additions and 2 deletions

View File

@ -130,6 +130,7 @@ namespace Wabbajack
this.WhenAny(x => x.ModListPath),
this.WhenAny(x => x.EnableSlideShow),
(modList, modListPath, enableSlideShow) => (modList, modListPath, enableSlideShow))
// Do any potential unzipping on a background thread
.ObserveOn(RxApp.TaskpoolScheduler)
.Select(u =>
{

View File

@ -11,6 +11,15 @@ namespace Wabbajack
{
public static class ReactiveUIExt
{
/// <summary>
/// Convenience function to not have to specify the selector function in the default ReactiveUI WhenAny() call.
/// Subscribes to changes in a property on a given object.
/// </summary>
/// <typeparam name="TSender">Type of object to watch</typeparam>
/// <typeparam name="TRet">The type of property watched</typeparam>
/// <param name="This">Object to watch</param>
/// <param name="property1">Expression path to the property to subscribe to</param>
/// <returns></returns>
public static IObservable<TRet> WhenAny<TSender, TRet>(
this TSender This,
Expression<Func<TSender, TRet>> property1)
@ -19,17 +28,31 @@ namespace Wabbajack
return This.WhenAny(property1, selector: x => x.GetValue());
}
/// <summary>
/// Convenience function that discards events that are null
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <returns>Source events that are not null</returns>
public static IObservable<T> NotNull<T>(this IObservable<T> source)
where T : class
{
return source.Where(u => u != null);
}
/// <summary>
/// Convenience wrapper to observe following calls on the GUI thread.
/// </summary>
public static IObservable<T> ObserveOnGuiThread<T>(this IObservable<T> source)
{
return source.ObserveOn(RxApp.MainThreadScheduler);
}
/// <summary>
/// Converts any observable to type Unit. Useful for when you care that a signal occurred,
/// but don't care about what its value is downstream.
/// </summary>
/// <returns>An observable that returns Unit anytime the source signal fires an event.</returns>
public static IObservable<Unit> Unit<T>(this IObservable<T> source)
{
return source.Select(_ => System.Reactive.Unit.Default);
@ -40,7 +63,6 @@ namespace Wabbajack
/// When the switch is on, the source will be subscribed to, and its updates passed through.
/// When the switch is off, the subscription to the source observable will be stopped, and no signal will be published.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source">Source observable to subscribe to if on</param>
/// <param name="filterSwitch">On/Off signal of whether to subscribe to source observable</param>
/// <returns>Observable that publishes data from source, if the switch is on.</returns>
@ -64,12 +86,18 @@ namespace Wabbajack
/// These snippets were provided by RolandPheasant (author of DynamicData)
/// They'll be going into the official library at some point, but are here for now.
#region Dynamic Data EnsureUniqueChanges
#region Dynamic Data EnsureUniqueChanges
/// <summary>
/// Removes outdated key events from a changeset, only leaving the last relevent change for each key.
/// </summary>
public static IObservable<IChangeSet<TObject, TKey>> EnsureUniqueChanges<TObject, TKey>(this IObservable<IChangeSet<TObject, TKey>> source)
{
return source.Select(EnsureUniqueChanges);
}
/// <summary>
/// Removes outdated key events from a changeset, only leaving the last relevent change for each key.
/// </summary>
public static IChangeSet<TObject, TKey> EnsureUniqueChanges<TObject, TKey>(this IChangeSet<TObject, TKey> input)
{
var changes = input