From d43365018aefd750e63a6657e9bd8f28cb313cb0 Mon Sep 17 00:00:00 2001 From: Kieran Bond Date: Thu, 26 Sep 2019 17:15:32 +0100 Subject: [PATCH] Mediator tracking and `IView.Ready()` function called once all mediators attached Functionality added by creating a list of Mediators being added to the `View`, and once those are done - we call the `Ready()` function on the `IView` interface #18 --- .../Bender/Extensions/Mediation/API/IView.cs | 2 + .../Mediation/Impl/MediatorViewHandler.cs | 12 ++++- .../Unity/Extensions/Mediation/Impl/View.cs | 45 ++++++++++--------- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/Robotlegs/Bender/Extensions/Mediation/API/IView.cs b/src/Robotlegs/Bender/Extensions/Mediation/API/IView.cs index 81d2991..d379863 100644 --- a/src/Robotlegs/Bender/Extensions/Mediation/API/IView.cs +++ b/src/Robotlegs/Bender/Extensions/Mediation/API/IView.cs @@ -12,6 +12,8 @@ namespace Robotlegs.Bender.Extensions.Mediation.API public interface IView { event Action RemoveView; + + void Ready(); } } diff --git a/src/Robotlegs/Bender/Extensions/Mediation/Impl/MediatorViewHandler.cs b/src/Robotlegs/Bender/Extensions/Mediation/Impl/MediatorViewHandler.cs index 41735dc..1a94dd9 100644 --- a/src/Robotlegs/Bender/Extensions/Mediation/Impl/MediatorViewHandler.cs +++ b/src/Robotlegs/Bender/Extensions/Mediation/Impl/MediatorViewHandler.cs @@ -59,10 +59,18 @@ public void RemoveMapping(IMediatorMapping mapping) public void HandleView(object view, Type type) { List interestedMappings = GetInterestedMappingsFor(view, type); - if (interestedMappings != null) + List mediators = new List(); + + if (interestedMappings != null) { - _factory.CreateMediators (view, type, interestedMappings); + mediators = _factory.CreateMediators (view, type, interestedMappings); } + + if(mediators != null && mediators.Count > 0) + { + if(view is IView) + (view as IView).Ready(); + } } /*============================================================================*/ diff --git a/src/Robotlegs/Bender/Platforms/Unity/Extensions/Mediation/Impl/View.cs b/src/Robotlegs/Bender/Platforms/Unity/Extensions/Mediation/Impl/View.cs index e596380..fb78e48 100644 --- a/src/Robotlegs/Bender/Platforms/Unity/Extensions/Mediation/Impl/View.cs +++ b/src/Robotlegs/Bender/Platforms/Unity/Extensions/Mediation/Impl/View.cs @@ -12,26 +12,31 @@ namespace Robotlegs.Bender.Platforms.Unity.Extensions.Mediation.Impl { - public class View : MonoBehaviour, IView - { - public event Action RemoveView - { - add - { - _removeView += value; - } - remove - { - _removeView -= value; - } - } - - private Action _removeView; - - protected virtual void Start () - { - ViewNotifier.RegisterView(this); - } + public class View : MonoBehaviour, IView + { + public event Action RemoveView + { + add + { + _removeView += value; + } + remove + { + _removeView -= value; + } + } + + private Action _removeView; + + protected virtual void Start() + { + ViewNotifier.RegisterView(this); + } + + public virtual void Ready() + { + + } protected virtual void OnDestroy () {