Skip to content

Commit

Permalink
Dox AutoPersistHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
anaisbetts committed Jul 3, 2014
1 parent e03b619 commit ac221df
Showing 1 changed file with 51 additions and 35 deletions.
86 changes: 51 additions & 35 deletions ReactiveUI/AutoPersistHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,39 @@ public static class AutoPersistHelper
}, RxApp.SmallCacheLimit);

/// <summary>
///
/// AutoPersist allows you to automatically call a method when an object
/// has changed, throttling on a certain interval. Note that this object
/// must mark its persistable properties via the [DataMember] attribute.
/// Changes to properties not marked with DataMember will not trigger the
/// object to be saved.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="This"></param>
/// <param name="doPersist"></param>
/// <param name="interval"></param>
/// <returns></returns>
/// <param name="doPersist">The asynchronous method to call to save the
/// object to disk.</param>
/// <param name="interval">The interval to save the object on. Note that
/// if an object is constantly changing, it is possible that it will never
/// be saved.</param>
/// <returns>A Disposable to disable automatic persistence.</returns>
public static IDisposable AutoPersist<T>(this T This, Func<T, IObservable<Unit>> doPersist, TimeSpan? interval = null)
where T : IReactiveObject
{
return This.AutoPersist(doPersist, Observable.Never<Unit>(), interval);
}

/// <summary>
///
/// AutoPersist allows you to automatically call a method when an object
/// has changed, throttling on a certain interval. Note that this object
/// must mark its persistable properties via the [DataMember] attribute.
/// Changes to properties not marked with DataMember will not trigger the
/// object to be saved.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="TDontCare"></typeparam>
/// <param name="This"></param>
/// <param name="doPersist"></param>
/// <param name="manualSaveSignal"></param>
/// <param name="interval"></param>
/// <returns></returns>
/// <param name="doPersist">The asynchronous method to call to save the
/// object to disk.</param>
/// <param name="manualSaveSignal">When invoked, the object will be saved
/// regardless of whether it has changed.</param>
/// <param name="interval">The interval to save the object on. Note that
/// if an object is constantly changing, it is possible that it will never
/// be saved.</param>
/// <returns>A Disposable to disable automatic persistence.</returns>
public static IDisposable AutoPersist<T, TDontCare>(this T This, Func<T, IObservable<Unit>> doPersist, IObservable<TDontCare> manualSaveSignal, TimeSpan? interval = null)
where T : IReactiveObject
{
Expand All @@ -75,7 +85,7 @@ public static IDisposable AutoPersist<T, TDontCare>(this T This, Func<T, IObserv
.SelectMany(_ => doPersist(This))
.Publish();

// NB: This rigamarole is to prevent the initialization of a class
// NB: This rigamarole is to prevent the initialization of a class
// from triggering a save
var ret = new SingleAssignmentDisposable();
RxApp.MainThreadScheduler.Schedule(() => {
Expand All @@ -87,29 +97,33 @@ public static IDisposable AutoPersist<T, TDontCare>(this T This, Func<T, IObserv
}

/// <summary>
///
/// Apply AutoPersistence to all objects in a collection. Items that are
/// no longer in the collection won't be persisted anymore.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="This"></param>
/// <param name="doPersist"></param>
/// <param name="interval"></param>
/// <returns></returns>
/// <param name="doPersist">The asynchronous method to call to save the
/// object to disk.</param>
/// <param name="interval">The interval to save the object on. Note that
/// if an object is constantly changing, it is possible that it will never
/// be saved.</param>
/// <returns>A Disposable to disable automatic persistence.</returns>
public static IDisposable AutoPersistCollection<T>(this ReactiveList<T> This, Func<T, IObservable<Unit>> doPersist, TimeSpan? interval = null)
where T : IReactiveObject
{
return AutoPersistCollection(This, doPersist, Observable.Never<Unit>(), interval);
}

/// <summary>
///
/// Apply AutoPersistence to all objects in a collection. Items that are
/// no longer in the collection won't be persisted anymore.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="TDontCare"></typeparam>
/// <param name="This"></param>
/// <param name="doPersist"></param>
/// <param name="manualSaveSignal"></param>
/// <param name="interval"></param>
/// <returns></returns>
/// <param name="doPersist">The asynchronous method to call to save the
/// object to disk.</param>
/// <param name="manualSaveSignal">When invoked, the object will be saved
/// regardless of whether it has changed.</param>
/// <param name="interval">The interval to save the object on. Note that
/// if an object is constantly changing, it is possible that it will never
/// be saved.</param>
/// <returns>A Disposable to disable automatic persistence.</returns>
public static IDisposable AutoPersistCollection<T, TDontCare>(this ReactiveList<T> This, Func<T, IObservable<Unit>> doPersist, IObservable<TDontCare> manualSaveSignal, TimeSpan? interval = null)
where T : IReactiveObject
{
Expand All @@ -132,13 +146,15 @@ public static IDisposable AutoPersistCollection<T, TDontCare>(this ReactiveList<
}

/// <summary>
///
/// Call methods 'onAdd' and 'onRemove' whenever an object is added or
/// removed from a collection. This class correctly handles both when
/// a collection is initialized, as well as when the collection is Reset.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="This"></param>
/// <param name="onAdd"></param>
/// <param name="onRemove"></param>
/// <returns></returns>
/// <param name="onAdd">A method to be called when an object is added
/// to the collection.</param>
/// <param name="onRemove">A method to be called when an object is removed
/// from the collection.</param>
/// <returns>A Disposable that deactivates this behavior.</returns>
public static IDisposable ActOnEveryObject<T>(this ReactiveList<T> This, Action<T> onAdd, Action<T> onRemove)
where T : IReactiveObject
{
Expand Down

0 comments on commit ac221df

Please sign in to comment.