diff --git a/src/ReactiveUI/Activation.cs b/src/ReactiveUI/Activation.cs index 1e28ab39b3..5a4eca44ec 100644 --- a/src/ReactiveUI/Activation.cs +++ b/src/ReactiveUI/Activation.cs @@ -54,6 +54,9 @@ public sealed class ViewModelActivator /// The deactivated. public IObservable Deactivated { get { return deactivated; } } + /// + /// Constructs a new ViewModelActivator + /// public ViewModelActivator() { blocks = new List>>(); @@ -87,8 +90,10 @@ public IDisposable Activate() /// This method is called by the framework when the corresponding View /// is deactivated. /// - /// Force the VM to be deactivated, even - /// if more than one person called Activate. + /// + /// Force the VM to be deactivated, even + /// if more than one person called Activate. + /// public void Deactivate(bool ignoreRefCount = false) { if (Interlocked.Decrement(ref refCount) == 0 || ignoreRefCount) { @@ -98,6 +103,9 @@ public void Deactivate(bool ignoreRefCount = false) } } + /// + /// A set of extension methods to help wire up View and ViewModel activation + /// public static class ViewForMixins { static ViewForMixins() @@ -110,9 +118,11 @@ static ViewForMixins() /// ViewModel's View is Activated. /// /// Object that supports activation. - /// The method to be called when the corresponding + /// + /// The method to be called when the corresponding /// View is activated. It returns a list of Disposables that will be - /// cleaned up when the View is deactivated. + /// cleaned up when the View is deactivated. + /// public static void WhenActivated(this ISupportsActivation This, Func> block) { This.Activator.addActivationBlock(block); @@ -123,10 +133,12 @@ public static void WhenActivated(this ISupportsActivation This, Func /// Object that supports activation. - /// The method to be called when the corresponding + /// + /// The method to be called when the corresponding /// View is activated. The Action parameter (usually called 'd') allows /// you to register Disposables to be cleaned up when the View is - /// deactivated (i.e. "d(someObservable.Subscribe());") + /// deactivated (i.e. "d(someObservable.Subscribe());") + /// public static void WhenActivated(this ISupportsActivation This, Action> block) { This.Activator.addActivationBlock(() => { @@ -141,9 +153,11 @@ public static void WhenActivated(this ISupportsActivation This, Action /// Object that supports activation. - /// The method to be called when the corresponding + /// + /// The method to be called when the corresponding /// View is activated. The Action parameter (usually called 'disposables') allows - /// you to collate all the disposables to be cleaned up during deactivation. + /// you to collate all the disposables to be cleaned up during deactivation. + /// public static void WhenActivated(this ISupportsActivation This, Action block) { This.Activator.addActivationBlock(() => { @@ -158,9 +172,11 @@ public static void WhenActivated(this ISupportsActivation This, Action /// Object that supports activation. - /// The method to be called when the corresponding + /// + /// The method to be called when the corresponding /// View is activated. It returns a list of Disposables that will be - /// cleaned up when the View is deactivated. + /// cleaned up when the View is deactivated. + /// /// A Disposable that deactivates this registration. public static IDisposable WhenActivated(this IActivatable This, Func> block) { @@ -172,12 +188,16 @@ public static IDisposable WhenActivated(this IActivatable This, Func /// Object that supports activation. - /// The method to be called when the corresponding + /// + /// The method to be called when the corresponding /// View is activated. It returns a list of Disposables that will be - /// cleaned up when the View is deactivated. - /// The IActivatable will ordinarily also host the View + /// cleaned up when the View is deactivated. + /// + /// + /// The IActivatable will ordinarily also host the View /// Model, but in the event it is not, a class implementing /// can be supplied here. + /// /// A Disposable that deactivates this registration. public static IDisposable WhenActivated(this IActivatable This, Func> block, IViewFor view) { @@ -204,10 +224,12 @@ public static IDisposable WhenActivated(this IActivatable This, Func /// Object that supports activation. - /// The method to be called when the corresponding + /// + /// The method to be called when the corresponding /// View is activated. The Action parameter (usually called 'd') allows /// you to register Disposables to be cleaned up when the View is - /// deactivated (i.e. "d(someObservable.Subscribe());") + /// deactivated (i.e. "d(someObservable.Subscribe());") + /// /// A Disposable that deactivates this registration. public static IDisposable WhenActivated(this IActivatable This, Action> block) { @@ -219,13 +241,17 @@ public static IDisposable WhenActivated(this IActivatable This, Action /// Object that supports activation. - /// The method to be called when the corresponding + /// + /// The method to be called when the corresponding /// View is activated. The Action parameter (usually called 'd') allows /// you to register Disposables to be cleaned up when the View is - /// deactivated (i.e. "d(someObservable.Subscribe());") - /// The IActivatable will ordinarily also host the View + /// deactivated (i.e. "d(someObservable.Subscribe());") + /// + /// + /// The IActivatable will ordinarily also host the View /// Model, but in the event it is not, a class implementing /// can be supplied here. + /// /// A Disposable that deactivates this registration. public static IDisposable WhenActivated(this IActivatable This, Action> block, IViewFor view) { @@ -241,12 +267,16 @@ public static IDisposable WhenActivated(this IActivatable This, Action /// Object that supports activation. - /// The method to be called when the corresponding + /// + /// The method to be called when the corresponding /// View is activated. The Action parameter (usually called 'disposables') allows - /// you to collate all disposables that should be cleaned up during deactivation. - /// The IActivatable will ordinarily also host the View + /// you to collate all disposables that should be cleaned up during deactivation. + /// + /// + /// The IActivatable will ordinarily also host the View /// Model, but in the event it is not, a class implementing /// can be supplied here. + /// /// A Disposable that deactivates this registration. public static IDisposable WhenActivated(this IActivatable This, Action block, IViewFor view = null) { @@ -262,7 +292,6 @@ static IDisposable handleViewActivation(Func> block, IO var viewDisposable = new SerialDisposable(); return new CompositeDisposable( - // Activation activation.Subscribe(activated => { // NB: We need to make sure to respect ordering so that the cleanup // happens before we invoke block again @@ -280,7 +309,6 @@ static IDisposable handleViewModelActivation(IViewFor view, IObservable ac var viewVmDisposable = new SerialDisposable(); return new CompositeDisposable( - // Activation activation.Subscribe(activated => { if (activated) { viewVmDisposable.Disposable = view.WhenAnyValue(x => x.ViewModel) @@ -315,16 +343,29 @@ static IDisposable handleViewModelActivation(IViewFor view, IObservable ac /// /// This class implements View Activation for classes that explicitly describe - /// their activation via ICanActivate. This class is used by the framework. + /// their activation via . This class is used by the framework. /// public class CanActivateViewFetcher : IActivationForViewFetcher { + /// + /// Returns a positive integer for derivates of the interface. + /// + /// The source type to check + /// + /// A positive integer if is supported, + /// zero otherwise + /// public int GetAffinityForView(Type view) { return (typeof(ICanActivate).GetTypeInfo().IsAssignableFrom(view.GetTypeInfo())) ? 10 : 0; } + /// + /// Get an observable defining whether the view is active + /// + /// The view to observe + /// An observable tracking whether the view is active public IObservable GetActivationForView(IActivatable view) { var ca = view as ICanActivate;